I want to stub GMarker#new to return the mock GMarker on line 223. I
also want to ensure that GMarker#new is being called once with certain
arguments, as seen on lines 227-229.
However, this spec fails, and the ‘gmarker’ variable is nil:
gmarker is a [NilClass]
F.
1)
NoMethodError in ‘RentalMap#make_marker should make a map marker’
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.a?
./spec/models/rental_map_spec.rb:233:
If I comment out lines 227-229, the spec succeeds, and the ‘marker’
variable is the expected mock object:
marker = [Spec::Mocks::Mock]
With lines 227-229 uncommented, why is the ‘gmarker’ variable nil?
223 mock_marker = mock ‘gmarker’
232 puts “marker is a [#{marker.class}]”
1)
NoMethodError in ‘RentalMap#make_marker should make a map marker’
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.a?
./spec/models/rental_map_spec.rb:233:
If I comment out lines 227-229, the spec succeeds, and the ‘marker’ variable
is the expected mock object:
marker = [Spec::Mocks::Mock]
With lines 227-229 uncommented, why is the ‘gmarker’ variable nil?
Do you have the latest code from git? If so this should work as
expected.
If I comment out lines 227-229, the spec succeeds, and the ‘marker’
variable
is the expected mock object:
marker = [Spec::Mocks::Mock]
With lines 227-229 uncommented, why is the ‘gmarker’ variable nil?
Do you have the latest code from git? If so this should work as
expected.
Hi David. I installed the rspec and rspec-rails plugins in my Rails
app on August 19, and haven’t updated them since. Was this
functionality added after August 19?
-Nick
I knew there was a dead simple answer to the question. Thanks, Tero.
That should work too, but recent changes support returning a
previously defined stub value when you don’t specify a return value in
a mock expectation: