Skip to content

Instantly share code, notes, and snippets.

@listrophy
Created March 21, 2009 20:13
Show Gist options
  • Save listrophy/82963 to your computer and use it in GitHub Desktop.
Save listrophy/82963 to your computer and use it in GitHub Desktop.
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe StoriesController do
def mock_story(stubs={})
@mock_story ||= mock_model(Story, stubs)
end
def mock_errors(stubs={})
unless @mock_errors
@mock_errors = mock(:errors, stubs)
@mock_errors.should_receive(:on).with(:text).and_return("error on :text")
end
@mock_errors
end
describe "POST create" do
describe "with invalid params" do
it "exposes a newly created but unsaved story as @story" do
story_mock = mock_story(:save => false)
story_mock.should_receive(:errors).and_return(mock_errors)
story_mock.stub!(:text).and_return("this is the text")
Story.stub!(:new).with({'these' => 'params'}).and_return(story_mock)
post :create, :story => {:these => 'params'}
assigns(:story).should equal(mock_story)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment