rubocop-rspec
rubocop-rspec copied to clipboard
Code style checking for RSpec files
I know this is weird, but I've seen code such as ``` expect(Foo).to receive(:bar).and_return(:baz) expect(subject.baz).to eq Foo.bar ``` (one very interesting example was `expect(Account).to receive(:all).once.and_return(Account.all)`) Such strange misuses of mocks...
Checking that the subject isn't being stubbed is good, but typically in unit testing you want to be sure not to stub the class that you're testing. Provided that the...
Example code: ``` RSpec.describe User do context 'admin' let(:admin) { create :user, role: admin } it '...' do expect(admin.something).to eq(result) end end ``` Generally when something is used in an...
We have some specs where we're defining classes inside specs like this: ```ruby describe 'Foo' do class Bar def initialize(name) @name = name end def execute p @name end end...
Extend MethodCallParentheses for DSL methods which are rspec related. Extend the list added in https://github.com/rubocop-hq/rubocop/pull/1069, to include methods such as `expect_with` and `belongs_to`. At the moment this have to be...
# Problem RSpec/ContextWording does not work well to check Japanese. It has two problems. First, usually we use a suffix to specify "when". For example, `when a user exists` is...
Rubocop complains when there is too many expectations but says nothing when we have `it` with some code not including any `expect`s. Maybe there is some sense to implement such...
`@see` declarations in cop descriptions are quite common: ``` lib/rubocop/cop/rspec/subject_stub.rb|8| 10: # @see https://robots.thoughtbot.com/don-t-stub-the-system-under-test lib/rubocop/cop/rspec/leaky_constant_declaration.rb|20| 10: # @see https://relishapp.com/rspec/rspec-mocks/docs/mutating-constants lib/rubocop/cop/rspec/context_wording.rb|8| 10: # @see https://github.com/reachlocal/rspec-style-guide#context-descriptions lib/rubocop/cop/rspec/context_wording.rb|9| 10: # @see http://www.betterspecs.org/#contexts lib/rubocop/cop/rspec/example_wording.rb|10|...
RSpec/HookArgument: Adding an EnforcedStyle of :all & accept both :each and :all as EnforcedStyle?
I am working in a huge codebase that has a pattern of using `before...do` syntax and it resulted in really slow test runs because a lot of setup is happening...
On our project we have a test as follows: ```ruby expect(get: :show, params: { id: 'null', format: :json }).not_to be_routable ``` Which is in turn raising a cop: ```ruby C:...