Skip to content

Instantly share code, notes, and snippets.

@beckyconning
Created August 9, 2012 20:21
Show Gist options
  • Save beckyconning/3307763 to your computer and use it in GitHub Desktop.
Save beckyconning/3307763 to your computer and use it in GitHub Desktop.
# There is no message object in the first example, and there needs to be one
# for the code in the action to run.
def create
message = Message.new(params[:message])
message.save
redirect_to :action => "index"
end
# We can get the first example to pass without impacting the second example by
# introducing a mock message:
it "creates a new message" do
message = mock_model(Message)
Message.should_receive(:new).with(
"text" => "a quick brown fox"
).and_return(message)
post :create, :message => { "text" => "a quick brown fox" }
end
# Here we create a mock message and then tell the Message class to return it
# in response to new( ).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment