5

I'm learning test in rails rspec. I have this part of test:

subject(:service) { described_class.new() }
context 'when sth' do
  it 'should sth' do
    expect ( service.call(@params) ).to eq(0)
  end
end

Service's method call return number. But I get something like this:

Failures:

 1) Module::Registration when sth should sth
 Failure/Error: expect ( service.call(@params) ).to eq(2)
 NoMethodError:
   undefined method `to' for 2:Fixnum
 # ./spec/module/registration_spec.rb:22:in `block (3 levels) in <module:Module>'

Finished in 2.48 seconds
1 example, 1 failure

So how can I check that method return correct "Number" variable using to?

1 Answer 1

5

You have to remove the space between expect and (:

expect( service.call(@params) ).to eq(0)
#    ^^

Otherwise Ruby evaluates the expression separately:

( service.call(@params) ).to
( 2 ).to
#=> undefined method `to' for 2:Fixnum
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.