rspec_spinner is a progress bar for RSpec which outputs failing examples as they happen (instead of all at the end). Installation gem install rspec_spinner Usage script/spec -r rspec...
...spinner -f RspecSpinner::Bar -c To make a shortcut in your .bashrc alias ss='script/spec -r rspec_spinner -f RspecSpinner::Bar -c' There's also an alternate runner RSpecSpinner::Spinner...
There seems to be no built-in matcher in RSpec to check if a string contains terms in the desired order. A simple workaround is to use a regular expression...
Inside before :each blocks you can refer to variables that you introduce via let later on. They do not need...
Better RSpec
...or false. That's why it has been renamed to be_truthy in recent RSpec versions. The same thing holds for be_false, which actually checks if a value is...
If you want to check for true or false in RSpec 2, write this instead: value.should == true value.should == false If you want to check for true or false...
When using the resource_controller gem you often hook onto events like this: update.before do do_something end
...deal.total_price).to eq BigDecimal(1200.99) If you don't like the syntax, our rspec_candy gem has a matcher that will compare Fixnums (integers), Floats and BigDecimals with each...
You can configure RSpec 3.3+ to raise an error when attempting to stub or mock a non-existing method. We strongly recommend to do this as non-verified stubs are...
You can enable this behavior by adding the following to your spec_helper.rb: RSpec.configure do |config| config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = true end end
This works in modern RSpecs (RSpec >= 2.x) and Cucumbers: rspec spec/models/node_spec.rb:294:322 cucumber features/nodes.feature:543:563:579 Also your features should be shorter than that...
Sometimes you need a piece of code to do something different for specs than for features. If you don't...
Never use raise_error without specifying the Error you expect. expect { do_a_lot_of_complicated_stuff }.to raise_error...
Reading user input in console applications is usually done using Kernel#gets. Stubbing that can be a bit hairy.
Passing the --profile flag to RSpec produces some additional output, namely the running times of the ten slowest examples in your specs...
In a Rails application, *_spec.rb files get special treatment depending on the file's directory. E.g. when you put a...
To only run a single describe/context block in a long spec, you can say spec spec/models/note_spec.rb:545 ... where the describe...
...original implementation of stubbed methods with unstub: object.stub(:foo => 'bar') # ... object.unstub(:foo) In recent RSpecs double is the preferred way to create a mock object (stub and mock are aliases...
If the argument list is the same every time: expect(object).to receive(:foo).with('argument').and_return('response 1...
betterspecs.org is a documentation on how to write better RSpec tests. Note that there are also other approaches like The Self-Contained Test, which is complementary to the dry-approches...
This finally works: User.any_instance.should_receive(...) as does User.any_instance.stub(...) Note: You won't have RSpec 2.6 if you're still working on Rails...
Never name your shared example group *_spec.rb. Otherwise rspec will try to load your example group as a spec and you will get the error above...
The attached RSpec matcher allows for comfortably testing delegation. Examples describe Post do it { should delegate(:name).to(:author).with_prefix } # post.author_name it { should delegate(:month).to(:created_at...
...to(:created_at) } end Credits go to txus. See the attached link for an RSpec 2+ version...
Back when Steak was first released, Capybara didn’t have any of the nice RSpec helpers it does now. A lot has changed since. Besides the helpers, it got its...
...own RSpec acceptance testing DSL recently, essentially eating Steak’s functionality and turning it into a complete acceptance testing solution (on top of RSpec...
To test whether a hash includes an expected sub-hash: expect(user.attributes).to match(hash_including('name' => 'Bruce Wayne'))
...rspec -b...