Skip to content

Commit

Permalink
provide a way to ensure a clean state between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bmabey committed Aug 24, 2009
1 parent 30fea0b commit 0eee638
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/faketwitter.rb
Expand Up @@ -16,6 +16,11 @@ def register_search(query, search_options = {})
)
end

def reset
FakeWeb.clean_registry
TweetFactory.reset
end

def new_tweet(attributes)
TweetFactory.create(attributes)
end
Expand Down
21 changes: 21 additions & 0 deletions spec/faketwitter_spec.rb
Expand Up @@ -152,7 +152,28 @@
tweets = FakeTwitter.tweets_from('ben')
tweets.map { |t| t['text'] }.should == ['goodbye', 'hello']
end
end

describe '::reset' do
it "tells FakeWeb to clean it's registry" do
FakeWeb.should_receive(:clean_registry)
FakeTwitter.reset
end
it "resets the user id counter for tweets" do
FakeTwitter.new_tweet('from_user' => 'foo')['from_user_id'].should == 1
FakeTwitter.reset
FakeTwitter.new_tweet('from_user' => 'bar')['from_user_id'].should == 1
end
it "resets the tweet id counter" do
FakeTwitter.new_tweet('from_user' => 'foo')['id'].should == 1
FakeTwitter.reset
FakeTwitter.new_tweet('from_user' => 'foo')['id'].should == 1
end
it "clears the sent tweets" do
FakeTwitter.new_tweet('from_user' => 'foo')
FakeTwitter.reset
FakeTwitter.tweets_from('foo').should be_empty
end
end

end

0 comments on commit 0eee638

Please sign in to comment.