[rspec-users] How to spec accessing a constant
Scott Taylor
mailing_lists at railsnewbie.com
Thu Oct 16 01:47:31 EDT 2008
On Oct 15, 2008, at 4:31 PM, Nick Hoffman wrote:
> Hi guys. One of my methods uses a constant in another method, like
> this:
>
> class A
> def something
> "foo: #{B::BAR}"
> end
> end
>
> When writing the spec for A#something , how would you mock or stub
> #{B::BAR}, and how would you set an expectation that B::BAR is used?
Just hide the constant behind a method, something like this:
class A
def something; "foo :#{bar}"; end
def bar; B::BAR; end
end
This allows you to stub the constant, if need be.
Scott
More information about the rspec-users
mailing list