In rpsec 2.12 I expected this helper method definition to work:
module X
private
def build_them(type)
puts 'Catching the star'
end
end
context 'public/private instance methods' do
subject{ Class.new { extend(::X) } }
def subject.build(type)
puts "Throwing a star"
build_them(type)
end
it{ should respond_to :build}
end
The actual result is a failed spec:
expected #<Class:0x00000002ea5f90> to respond to :build
I expected the example to pass
Any suggestions on how to do this correctly?
Calling
subjectwithout passsing a block actually returns the ‘subject’ block in proc form. This means that in your code, when you do this:You are actually defining ‘build’ on the proc itself, not the object that the proc returns.
In the
it {...}example block, the expectations are executed against the object that the proc returns, so the test fails as you’ve seen.To make the test pass, you would need to define the ‘build’ method on the actual object that the ‘subject’ block will return:
Note that
describemust be used as the top level context,contextmust be nested