Reputation: 421
I don't have any code as this is just a hypothetical question, but how would you go about accessing and manipulating instance variables in rspec?
For instance if you had a @counter variable in your initialize method inside of a class, how could you write a test saying that if @counter is a certain number, then a certain method should return true. And if it equals a different number, then that method should return false.
Upvotes: 1
Views: 526
Reputation: 45943
describe Foo do
context 'When counter is even' do
let( :foo ){ Foo.new(4) }
specify '#even?' do
expect( foo.even? ).to be_true
end
end
end
According to your question, @counter
is set in the initialize method. So the #even?
method would check @counter
.
Upvotes: 1