[rspec-users] Rspec2 mock assign - how do I get the value out?

Kristian Mandrup kmandrup at gmail.com
Wed Jun 9 17:46:08 EDT 2010


assign(:message, stub("Message"))

In my view I can access the message, but...

<%= @message.to_s %>

    expected the following element's content to include "Hello
world!":
    #[RSpec::Mocks::Mock:0x81bbd81c @name="Message"]

Finally after some trial and error I discovered the solution, an
option on the stub call to set the text message (content of the stub)

    assign(:message, stub("Message", :text => "Hello world!"))

and in my view
<%= @message.text %>

Nice!


More information about the rspec-users mailing list