Skip to content

Instantly share code, notes, and snippets.

@josevalim
Created February 6, 2009 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josevalim/59412 to your computer and use it in GitHub Desktop.
Save josevalim/59412 to your computer and use it in GitHub Desktop.
# TasksController
describe TasksController do
describe "responding to GET show" do
receive :find, :on => Task, :with => '37', :and_return => :mock_task
get :show, :id => '37'
it { should match_expectations }
it { should ensure_assign(:project, :task).equal(mock_project, mock_task) }
end
end
# If tasks belongs_to project...
describe TasksController do
receive :find_by_title, :on => Project, :with => '42', :and_return => :mock_project
receive :tasks, :on => :mock_project, :and_return => Task
action :all, :project_id => '42'
describe "responding to GET show" do
receive :find, :with => '37', :and_return => :mock_task
get :show, :id => '37'
it { should match_expectations }
it { should ensure_assign(:project, :task).equal(mock_project, mock_task) }
end
end
# With some send aliases...
describe TasksController do
receives :find_by_title, :on => Project, :with => '42', :and_return => :mock_project
which :receives, :tasks, :and_return => Task
action :all, :project_id => '42'
describe "responding to GET show" do
receives :find, :on => Task, :with => '37', :and_return => :mock_task
and_then :get, :show, :id => '37'
it { should match_expectations }
it { should ensure_assign(:project, :task).equal(mock_project, mock_task) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment