Permalink
Browse files

Get most of the scenario green

  • Loading branch information...
1 parent 60265af commit 74cf339bd6c9be453aee9838466c5e9eae7854c6 @joshuaclayton committed Mar 27, 2012
View
@@ -10,6 +10,8 @@ group :test, :development do
gem "cucumber-rails", require: false
gem "rspec-rails"
gem "database_cleaner"
+ gem "mocha"
+ gem "bourne"
end
group :assets do
View
@@ -30,6 +30,8 @@ GEM
multi_json (~> 1.0)
addressable (2.2.7)
arel (3.0.2)
+ bourne (1.1.1)
+ mocha (= 0.10.4)
builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
@@ -81,7 +83,10 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
+ metaclass (0.0.1)
mime-types (1.18)
+ mocha (0.10.4)
+ metaclass (~> 0.0.1)
multi_json (1.2.0)
multipart-post (1.1.5)
nokogiri (1.5.0)
@@ -163,11 +168,13 @@ PLATFORMS
ruby
DEPENDENCIES
+ bourne
coffee-rails (~> 3.2.1)
cucumber-rails
database_cleaner
high_voltage
jquery-rails
+ mocha
rails (= 3.2.2)
rspec-rails
sass-rails (~> 3.2.3)
@@ -1,6 +1,6 @@
class SearchesController < ApplicationController
def show
- @tweets = Twitter.search(search_term)
+ @tweets = Searcher.new(search_term).search
render json: @tweets.to_json
end
@@ -1,3 +1,12 @@
class Searcher
+ class_attribute :search_class
+ self.search_class = Twitter
+ def initialize(search_term)
+ @search_term = search_term
+ end
+
+ def search
+ search_class.search(@search_term)
+ end
end
@@ -11,10 +11,10 @@ Feature: Search Twitter
Scenario: Search Twitter with known results
Given Twitter responds to the search "#rails" with the tweets:
| text |
- | #rails is amazing |
+ | #Rails is amazing |
| I love #rails |
| #rails is cool, but #backbone is cooler |
- | Fuck #rails |
+ | Fuck #Rails |
And Twitter responds to the search "#ruby" with the tweets:
| text |
| #ruby is pretty great |
@@ -5,7 +5,7 @@
end
Then /^I should see tweets containing "([^"]*)"$/ do |tweet_text|
- wait_until { all("ul.tweets li").count == 15 }
+ wait_until(15) { all("ul.tweets li").count == 15 }
search_term = /#{tweet_text}/i
@@ -0,0 +1,8 @@
+Before do
+ @original_search_class = Searcher.search_class
+ Searcher.search_class = TwitterMock
+end
+
+After do
+ Searcher.search_class = @original_search_class
+end
@@ -2,7 +2,7 @@
describe Searcher do
it "returns search results" do
- Searcher.search_class.stub(:search)
+ Searcher.search_class.stubs(:search)
Searcher.new("my awesome search terms").search
Searcher.search_class.should have_received(:search).with("my awesome search terms")
end
@@ -7,4 +7,12 @@
results.first.text.should == "my great tweet!"
end
+
+ it "allows for stubbing a search response" do
+ TwitterMock.stub_search_response("term", [{"text" => "my great tweet!"}])
+ TwitterMock.stub_search_response("awesome", [{"text" => "heck yeah"}])
+
+ TwitterMock.search("term").first.text.should == "my great tweet!"
+ TwitterMock.search("awesome").first.text.should == "heck yeah"
+ end
end
View
@@ -13,7 +13,7 @@
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
- # config.mock_with :mocha
+ config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
@@ -1,11 +1,12 @@
class TwitterMock
def self.stub_search_response(search_term, results)
- @results = results.map do |result|
+ @results ||= {}
+ @results[search_term] = results.map do |result|
Twitter::Status.new(result)
end
end
def self.search(search_term)
- @results
+ @results[search_term]
end
end

0 comments on commit 74cf339

Please sign in to comment.