rspec-style-guide icon indicating copy to clipboard operation
rspec-style-guide copied to clipboard

Best practices for writing your specs!

Results 20 rspec-style-guide issues
Sort by recently updated
recently updated
newest added

Content below exists in guide from the initial version ``` Add an example ensuring that the model created with FactoryBot.create is valid. describe Article do it 'is valid with valid...

There's a number of methods that have modern counterparts, recommend using the new ones instead.

The guide still has a section for controller specs. I think it should be mentioned that they have been deprecated and discouraged since Rails 3 (or was it 4?). I...

help wanted

Only use `before` and `let`, when there's a compelling benefit, don't use them as the default way to write specs. https://reddit.com/r/ruby/comments/73nrhk/ama_the_authors_of_effective_testing_with_rspec_3/dnsyanp/ An example I can think of: ```ruby # bad...

controversial

Don't overuse hooks, prefer explicitness. Helper methods are more explicit and even provide more flexibility An example off the top of my head: ```ruby # bad let(:article) { Article.new }...

In addition to `verify_partial_doubles` the above option may come handy to verify that you are stubbing an existing constant. ``` # When this is set to true, an error will...

Taken from Effective Testing with RSpec book. There's a matching [`RSpec/UnspecifiedException`](https://github.com/rubocop-hq/rubocop-rspec/blob/cc158decc3df402751e463843fb82ad718a58955/lib/rubocop/cop/rspec/unspecified_exception.rb#L6) cop in RuboCop-RSpec. [Example problem](https://github.com/rspec/rspec-mocks/pull/550) with it. The negated form has the opposite problem, and the exception should **not**...

Metadata is very useful and is able to include shared contexts, include group/example-specific helpers and hooks.

This is specific to rspec-rails: The generator originally created a helper which required everything in `support/**/*.rb`. This was changed in https://github.com/rspec/rspec-rails/pull/1137 but I still find many projects which require all...

It's strange that the guide is missing that.