logo
down
shadow

How to filter out one method call from many others with `expect().to receive()` in RSpec


How to filter out one method call from many others with `expect().to receive()` in RSpec

By : user3100421
Date : January 12 2021, 07:00 PM
fixed the issue. Will look into that further It's a good practice to give one responsability to one method.
In your case I guess you would like to test that your method return "A" and also "B".
code :
def print_a
  ClassB.print_letter("a")
end

def print_b
  ClassB.print_letter("b")
end

def self.my_method
    print_a
    print_b
  end
it " Print a" do
  expect(print_a).to eq 'a'
end


Share : facebook icon twitter icon
rspec undefined method `receive' for expect syntax

rspec undefined method `receive' for expect syntax


By : siva
Date : March 29 2020, 07:55 AM
This might help you Use of the expect syntax for message expectations was introduced in RSpec 2.14, per http://myronmars.to/n/dev-blog/2013/07/rspec-2-14-is-released. (Note: RSpec 2.4 is ten minor versions earlier than RSpec 2.14, per the recommended http://semver.org/.)
Change the Gemfile to be 2.14, e.g. gem 'rspec', '2.14' and do bundle
RSpec expect to receive method with array but order does not matter

RSpec expect to receive method with array but order does not matter


By : MusicLife
Date : March 29 2020, 07:55 AM
it fixes the issue You can pass any RSpec matcher to with, and contain_exactly(1, 2, 3) does exactly what you want, so you can pass that to with:
code :
expect(calculation_service).to receive(:sum?).with(contain_exactly(1, 2, 3)) { 6 }
expect(calculation_service).to receive(:sum?).with(
  a_collection_containing_exactly(1, 2, 3)
) { 6 }
Rspec expect method to receive ActiveRecord::Relation

Rspec expect method to receive ActiveRecord::Relation


By : Waseem Sangrar
Date : March 29 2020, 07:55 AM
seems to work fine Instead of faking bars, you could check that bars is the value you expect:
code :
expect(described_class).to receive(:foo) do |bars|
    # verify bars here. You could do bars.to_a and check the array 
    # or bars.to_sql and check the generated sql.
end
rspec expect child to receive method when parent method is called

rspec expect child to receive method when parent method is called


By : testingtester
Date : March 29 2020, 07:55 AM
I wish this help you After a lot more digging, the issue is that my comment variable isn't actually exactly the same instance as the variable that RSpec sees in the loop. They differ by the Rails object ID that is assigned on the fly.
I needed to use a spy or stub the method to avoid this issue.
Rspec expect(instance) to receive method not working as expected

Rspec expect(instance) to receive method not working as expected


By : Mohammad Shannak
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Firstly you need to stub the lines in controller in order to expect some code
shadow
Privacy Policy - Terms - Contact Us © festivalmusicasacra.org