Skip to content

Instantly share code, notes, and snippets.

@lazyatom
Forked from anonymous/gist:163826
Created August 7, 2009 10:32
Show Gist options
  • Save lazyatom/163827 to your computer and use it in GitHub Desktop.
Save lazyatom/163827 to your computer and use it in GitHub Desktop.
context "A user posting to a blog" do
setup do
@user = Factory(:user)
@blog = Factory(:blog)
end
action do
post :create, :user_id => @user.id, :id => @blog.id, :post => {:body => "Blah"}
end
# the body of this block is actually executed after 'setup' but before 'action'
expect "send a notification to Technorati or whatever" do
TechnoratiApi.expects(:notify)
end
expect "kill a kitten" do
KittyKiller.expects(:murder_randomly)
end
should "put the post into the users's posts" do
assert @user.posts.include?("Blah") # or whatever
end
# etc
end
How it all runs
------------
three 'tests' are generated:
test: A user posting to a blog should send a notification to Technorati or whatever
- setup runs
- Technorati expectation is setup
- action runs
- test body is empty
- expectations are then implicitly handled by mocha as normal
test: A user posting to a blog should kill a kitten
- setup runs
- KittyKiller expectation is setup
- action runs
- test body is empty
- expectations are then implicitly handled by mocha as normal
test: A user posting toa blog should put the post into the user's posts
- setup runs
- action runs
- test body runs and assertions are handled by test/unit as normal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment