RSpec's context (which is basically an alias for describe) takes over your whole application. No object may have its own context method, or you will always receive errors like...

The attached RSpec matcher exist_in_database checks if a given record still exists in the database and has not been destroyed: describe Ticket do describe '.purge_expired' do

...in the current branch since master: git diff --name-only master -- ./spec | xargs -I{} rspec {} If you have several spec folders add them for path parameter after ./spec accordingly.

rspec.info

...You should always try to fix those instead of rerunning them regularly. Setup Configure RSpec to persist the result of your test runs to a file. This is necessary to...

...status_persistence_file_path = 'spec/examples.txt' Rerun all failed examples using --only-failures bundle exec rspec --only-failures (or g rs --only-failures with geordi) will rerun all examples which failed...

If an view spec crashes due to undefined helper methods, you can enable this option: # config/application.rb config.action_controller.include_all_helpers = true...

In contrast to RSpec's included allow_value matcher, the attached matcher will also work on associations, which makes it ideal for testing assignable_values. Usage example describe Unit do...

...building, other_building) expect(unit.assignable_buildings).not_to include(unauthorized_building, nil) end ... See RSpec: Where to put custom matchers and other support code

...seems to be obvious, but you can expect Rake tasks to be called in RSpec. it 'deletes all Users' do FactroyBot.create(:user) expect(Rake::Task['notify:critical_operation']).to receive...

RSpec is smart when using the include-matcher in combination with .not_to. One could assume that .not_to include(3, 4, 5) evaluates to: NOT( .to include...

...truth value. It instead negates the individual include-expectations for each argument. Proof describe 'RSpec' do it "doesn't use logical negation for include, exhibit A" do

...JSON.parse(User.last.to_json)['created_at'] #=> "2001-01-01T00:00:00.000+00:00" In RSpec you might want to use .to_json instead of .iso8601 to use the build-in...

tl;dr You can use ordered to ensure that messages are received in a specific order. Example expect(ClassA).to...

To check which elements an ActiveRecord relation contains use the contain_exactly matcher. describe User do let!(:admin) { create(:user...

The ActionDispatch module of Rails gives you the helper method flash to access the flash messages in a response.

tl;dr: Upgrade the gem to at least 4.0.1 When you use rspec_rails in a version < 4 with Rails 6.1 you may encounter an error like this: Failure/Error:

...spec, so I first thought it could be the name of my Actor model. RSpec.describe Actor do it 'is valid with a name and birthday' do actor = Actor.new(name: 'Christian...

Within development and test environments, Rails is usually configured to show a detailed debug page instead of 404s. However, there...

Though nowhere to be found in the official docs, this works just fine. describe Facebook::Post do it_behaves_like...

RSpec's let allows you to super into "outside" definitions, in parent contexts. Example: describe '#save' do subject { described_class.new(attributes) } let(:attributes) { title: 'Example', user: create(:user) } it 'saves' do...

The Basic Authentication header encodes username and password. Effectively, it's just Base64 plus a "Basic" prefix.

...specs immediately or to get an overview of the core functionalities, you can use RSpec's "nested" format. It looks like this: Tool validations should require model to be set...

...should find tools by model and maker should find tools by serial number Call RSpec like this in order to use the nested format: spec spec -f documentation

Sometimes you need complex expectations on method arguments like this SomeApi.should_receive(:find).with(:query => '*foo*', :sort => 'timestamp ASC', :limit...

web.archive.org

@user = User.make end # ... end Furthermore, you will probably run into trouble with your RSpec configuration block that does things in config.before(:example), as this will also be run after...

You will need to upgrade to RSpec >= 2 and rspec-rails >= 2 for Rails 3. Here are some hints to get started: In RSpec 2 the executable is rspec, not...

RSpec and rspec-rails have been completely refactored internally. All RSpec classes have been renamed from Spec::Something to RSpec::Something. This also means that every require 'spec/something' must...

RSpec 1 (Rails 2) With the most recent spec_candy.rb helpers you can say: User.stub_any_instance(:foo => :bar) user = User.new user.foo # => :bar RSpec 2 (Rails 3) RSpec 2 comes with...

...this feature built in: User.any_instance.stub(:foo => :bar) user = User.new user.foo # => :bar RSpec 3 RSpec Mocks 3.3: any_instance allow_any_instance_of(User).to receive(:foo).and_return(:bar)

github.com

By default, Cucumber uses mocha. This note shows to use RSpec stubs and mocks instead. Rspec 1 / Rails 2 Put the following into your env.rb: require 'spec/stubs/cucumber' Rspec 2 / Rails...

RSpec 1, RSpec 2 To test whether two arrays have the same elements regardless of order, RSpec 1 and 2 give you the =~ matcher: actual_array.should =~ expected_array Rspec 3

...RSpec 3's expect syntax you can choose one of these two matchers: expect(actual_array).to match_array(['1', '2', '3']) expect(actual_array).to contain_exactly...