Skip to content

Commit

Permalink
updating the twitter generator to use cucumber by default now too
Browse files Browse the repository at this point in the history
  • Loading branch information
atmos committed Jul 5, 2009
1 parent 1978a87 commit a3b7329
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/generators/twitter/templates/Rakefile
Expand Up @@ -2,7 +2,6 @@ require 'rubygems'
require 'rake/gempackagetask'
require 'rubygems/specification'
require 'date'
require 'spec/rake/spectask'

GEM = "<%= name %>"
GEM_VERSION = "0.0.1"
Expand Down Expand Up @@ -51,8 +50,15 @@ task :make_spec do
end
end

task :default => :spec
task :default => :features

require 'cucumber/rake/task'
desc "Run cucumber"
Cucumber::Rake::Task.new do |t|
t.cucumber_opts = %w{--format pretty}
end

require 'spec/rake/spectask'
desc "Run specs"
Spec::Rake::SpecTask.new do |t|
t.spec_files = FileList['spec/**/*_spec.rb']
Expand Down
@@ -0,0 +1,16 @@
Feature: Viewing my wish list
In order to display a users' preferences
As a twitter user

Background:
Given I am logged in
And I have created a "53cm Pistas" category
And I have created a "54cm Cyclocross" category

Scenario: After Authenticating
When I visit the bookmarklet page
And I set the category to "53cm Pistas"
And the "description" is set to "Bianchi Pista Size 53cm Medium - $500 (Downtown Denver)"
And the "url" is set to "http://denver.craigslist.org/bik/1195971789.html"
When I click submit
Then I should see the window close
@@ -0,0 +1,19 @@
Feature: Viewing my wish list
In order to display a users' preferences
As a twitter user

Background:
Given I am logged in
And I have created a "53cm Pistas" category

Scenario: Posting to an existing category
When I post "Bianchi Pista Size 53cm Medium - $500 (Downtown Denver)" with a url of "http://denver.craigslist.org/bik/1195971789.html" to the "53cm Pistas" category
And I visit the "53cm Pistas" page
Then I should see the "Bianchi Pista Size 53cm Medium - $500 (Downtown Denver)" in the list
And the url should be set to "http://denver.craigslist.org/bik/1195971789.html"

Scenario: Posting to a new category
When I post "Bianchi Pista Size 54cm Medium - $500 (Downtown Denver)" with a url of "http://denver.craigslist.org/bik/1195971789.html" to the "54cm Pistas" category
And I visit the "54cm Pistas" page
Then I should see the "Bianchi Pista Size 54cm Medium - $500 (Downtown Denver)" in the list
And the url should be set to "http://denver.craigslist.org/bik/1195971789.html"
11 changes: 11 additions & 0 deletions lib/generators/twitter/templates/features/basics.feature.erb
@@ -0,0 +1,11 @@
Feature: Visiting the Home Page
In order to display a splash page

Scenario: Seeing the splash page unauthenticated
When I visit the home page
Then I should be prompted to try the app

Scenario: Seeing the splash page authenticated
Given I am logged in
When I visit the home page
Then I should be greeted
@@ -0,0 +1,15 @@
When /^I visit the home page$/ do
get '/'
end

Then /^I should be greeted$/ do
last_response.should have_selector("h2:contains('Hello There, you little twitterer!')")
end

Then /^I should be prompted to try the app$/ do
last_response.should have_selector("p:contains('Would you mind trying out my new app')")
end

Given /^I am logged in$/ do
login_quentin
end
63 changes: 63 additions & 0 deletions lib/generators/twitter/templates/features/support/env.rb.erb
@@ -0,0 +1,63 @@
require 'spec'
require 'spec/mocks'
require 'webrat'
require 'rack/test'
require 'dm-sweatshop'
require 'pp'

require File.dirname(__FILE__)+'/../../lib/<%= name %>'

module <%= name.camelize %>::AppHelpers
def app
@app = Rack::Builder.new do
run <%= name.camelize %>::App
end
end

def login_quentin
response = Net::HTTPSuccess.new('1.0', 200, nil)
response.body = "{\"description\":\"lulz\",\"profile_background_image_url\":\"http:\\/\\/static.twitter.com\\/images\\/themes\\/theme3\\/bg.gif\",\"utc_offset\":-25200,\"friends_count\":157,\"profile_background_color\":\"EDECE9\",\"profile_text_color\":\"634047\",\"url\":\"http:\\/\\/example.org\",\"name\":\"Quentin Blake\",\"favourites_count\":6,\"profile_link_color\":\"088253\",\"protected\":false,\"status\":{\"truncated\":false,\"in_reply_to_status_id\":null,\"text\":\"stu stu studio\",\"in_reply_to_user_id\":null,\"favorited\":false,\"created_at\":\"Tue Mar 31 19:02:12 +0000 2009\",\"id\":1426242614,\"source\":\"<a href=\\\"http:\\/\\/iconfactory.com\\/software\\/twitterrific\\\">twitterrific<\\/a>\"},\"created_at\":\"Sun Mar 18 20:07:13 +0000 2007\",\"statuses_count\":2560,\"profile_background_tile\":false,\"time_zone\":\"Mountain Time (US & Canada)\",\"profile_sidebar_fill_color\":\"E3E2DE\",\"profile_image_url\":\"http:\\/\\/static.twitter.com\\/images\\/default_profile_normal.png\",\"notifications\":false,\"profile_sidebar_border_color\":\"D3D2CF\",\"location\":\"Boulder, Colorado\",\"id\":1484261,\"following\":false,\"followers_count\":368,\"screen_name\":\"caboose\"}"
login(response)
end

def unauthorized_quentin
response = Net::HTTPUnauthorized.new('1.0', 401, nil)
response.body = "Unauthorized"
lambda { login(response) }.should raise_error(ArgumentError)
end

def login(response)
token = 'oU5W1XD2TTZhWT6Snfii9JbVBUkJOurCKhWQHz98765'

consumer = mock('Consumer', {:request => response})
request_token = mock('RequestToken', {:get_access_token => mock('AccessToken', {:token => 'foo', :secret => 'bar'})})

OAuth::Consumer.stub!(:new).and_return(consumer)
OAuth::RequestToken.stub!(:new).and_return(request_token)

visit "/callback?oauth_token=#{token}"
end
end

Webrat.configure do |config|
config.mode = :rack_test
config.application_port = 4567
end

class Net::HTTPResponse
def body=(content)
@body = content
@read = true
end
end

World(Rack::Test::Methods)
World(Spec::Mocks::ExampleMethods)
World(Webrat::Methods)
World(Webrat::Matchers)
World(<%= name.camelize %>::AppHelpers)

Before do
DataMapper.setup(:default, "sqlite3://:memory:")
DataMapper.auto_migrate!
end
@@ -0,0 +1,14 @@
Feature: Viewing my wish list
In order to display a users' preferences
As a twitter user

Background:
Given I am logged in
And I have created a "53cm Pistas" category

Scenario: After Authenticating
When I visit the home page
Then I should see my list of categories
When I enter "Prostitutes" for a new category
And I click submit
Then I should see the "Prostitutes" list
@@ -0,0 +1,6 @@
Feature: Visiting the Home Page
In order to display a splash page
As an anonymous user
Scenario: Seeing the splash page
When I visit the home page
Then I should be greeted
2 changes: 0 additions & 2 deletions lib/generators/twitter/templates/lib/templates.rb.erb
Expand Up @@ -5,8 +5,6 @@ require 'json'
gem 'haml', '~>2.0.9'
require 'haml/util'
require 'haml/engine'
gem 'chronic'
require 'chronic'
gem 'curb'
require 'curb'
require 'logger'
Expand Down
8 changes: 8 additions & 0 deletions lib/generators/twitter/twitter_generator.rb
Expand Up @@ -19,6 +19,8 @@ def manifest
m.directory ''
BASEDIRS.each { |path| m.directory path }
m.directory "lib/#{name}"
m.directory "features/support"
m.directory "features/step_definitions"
m.directory "lib/#{name}/sinatra"
m.directory "lib/#{name}/models"
m.directory "lib/#{name}/views"
Expand All @@ -29,6 +31,12 @@ def manifest
m.template "lib/templates/sinatra/app.rb.erb", "lib/#{name}/sinatra/app.rb"
m.template "lib/templates/models/user.rb.erb", "lib/#{name}/models/user.rb"

# cucumber stubs
m.template "features/support/env.rb.erb", "features/support/env.rb"
m.template "features/basics.feature.erb", "features/#{name}.feature"
m.template "features/step_definitions/basics.rb.erb", "features/step_definitions/#{name}.rb"

# rspec stubs
m.template "spec/spec_helper.rb.erb", "spec/spec_helper.rb"
m.template "spec/templates_spec.rb.erb", "spec/#{name}_spec.rb"
m.template "spec/fixtures.rb.erb", "spec/fixtures.rb"
Expand Down

0 comments on commit a3b7329

Please sign in to comment.