-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Trasbo
committed
Dec 3, 2010
1 parent
8124770
commit c67d578
Showing
11 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.gem | ||
Gemfile.lock | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
Given /^I have a Sinatra app with Cucumber and OmniAuth$/ do | ||
FileUtils.rm_rf(App::ROOT) | ||
FileUtils.cp_r(File.join(ROOT, 'fixtures/app'), App::ROOT) | ||
end | ||
|
||
When /^I add a "([^"]*)" feature with:$/ do |name, text| | ||
App.open_file("features/#{name.downcase.gsub(' ', '_')}.feature", 'w') do |f| | ||
f.write "Feature: #{name}\n\n" | ||
f.write text.split("\n").collect { |l| " #{l}" }.join("\n") | ||
end | ||
end | ||
|
||
When /^I add the "([^"]*)" strategy to the middleware stack$/ do |strategy| | ||
app = File.read(File.join(App::ROOT, 'app.rb')) | ||
|
||
App.open_file('app.rb', 'w') do |f| | ||
f.write app.gsub( | ||
/(enable :sessions)/, | ||
"\\1\n\nuse OmniAuth::Strategies::Twitter, 'KEY', 'SECRET'" | ||
) | ||
end | ||
end | ||
|
||
When /^I add a link to "([^"]*)" with the text "([^"]*)" to the homepage$/ do |url, text| | ||
When "I add the following to my Sinatra app:", | ||
"get '/' do\n '<a href=\"#{url}\">#{text}</a>'\nend" | ||
end | ||
|
||
When /^I add the following step definition to the user steps:$/ do |text| | ||
App.open_file('features/step_definitions/user_steps.rb', 'a') do |f| | ||
f.write "#{text}\n\n" | ||
end | ||
end | ||
|
||
When /^I add the following to my Sinatra app:$/ do |text| | ||
App.open_file('app.rb', 'a') do |f| | ||
f.write "\n#{text}\n" | ||
end | ||
end | ||
|
||
Then /^the features should pass$/ do | ||
RVM.gemset.use! 'oa-testing-test' | ||
|
||
FileUtils.cd(App::ROOT) do | ||
cucumber_output = `BUNDLE_GEMFILE="#{App::ROOT}/Gemfile" cucumber` | ||
end | ||
|
||
if $?.exitstatus != 0 | ||
raise cucumber_output | ||
end | ||
|
||
RVM.gemset.use! 'oa-testing' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module App | ||
ROOT = File.join(::ROOT, 'tmp/app') | ||
|
||
def open_file(file, mode) | ||
File.open(File.join(ROOT, file), mode) do |f| | ||
yield f | ||
end | ||
end | ||
module_function :open_file | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
require 'bundler/setup' | ||
$: << File.expand_path("~/.rvm/lib") | ||
require 'rvm' | ||
|
||
ROOT = File.expand_path(File.join(File.dirname(__FILE__), '../..')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Feature: Twitter | ||
|
||
Scenario: | ||
Given I have a Sinatra app with Cucumber and OmniAuth | ||
When I add a "User signs up" feature with: | ||
""" | ||
Scenario: The user chooses to authorize through Twitter | ||
Given I am on the homepage | ||
When I follow "Sign up using Twitter" | ||
And I authorize the app to read my Twitter info | ||
Then I should see an OmniAuth hash of my Twitter info | ||
""" | ||
And I add the "Twitter" strategy to the middleware stack | ||
And I add a link to "/auth/twitter" with the text "Sign up using Twitter" to the homepage | ||
And I add the following step definition to the user steps: | ||
""" | ||
When /^I authorize the app to read my Twitter info$/ do | ||
visit '/auth/twitter/callback' | ||
end | ||
""" | ||
And I add the following to my Sinatra app: | ||
""" | ||
get '/auth/twitter/callback' do | ||
request.env['omniauth.auth'].to_yaml | ||
end | ||
""" | ||
And I add the following step definition to the user steps: | ||
""" | ||
Then /^I should see an OmniAuth hash of my Twitter info$/ do | ||
auth_hash = YAML.load(response.body) | ||
auth_hash['provider'].should == 'twitter' | ||
auth_hash['user_info']['name'].should == 'James Garcia' | ||
end | ||
""" | ||
Then the features should pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
source 'http://rubygems.org/' | ||
|
||
gem 'sinatra' | ||
gem 'omniauth' | ||
gem 'cucumber' | ||
gem 'rspec' | ||
gem 'rack-test' | ||
gem 'webrat' | ||
gem 'fakeweb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'bundler/setup' | ||
require 'sinatra' | ||
require 'omniauth' | ||
|
||
enable :sessions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"follow_request_sent": false, | ||
"profile_use_background_image": true, | ||
"id": 218183011, | ||
"verified": false, | ||
"profile_sidebar_fill_color": "DDEEF6", | ||
"profile_text_color": "333333", | ||
"followers_count": 1, | ||
"profile_sidebar_border_color": "C0DEED", | ||
"location": null, | ||
"profile_background_color": "C0DEED", | ||
"id_str": "218183011", | ||
"utc_offset": null, | ||
"statuses_count": 0, | ||
"description": null, | ||
"friends_count": 0, | ||
"profile_link_color": "0084B4", | ||
"profile_image_url": "http://s.twimg.com/a/1290206336/images/default_profile_4_normal.png", | ||
"notifications": false, | ||
"show_all_inline_media": false, | ||
"geo_enabled": false, | ||
"profile_background_image_url": "http://s.twimg.com/a/1290206336/images/themes/theme1/bg.png", | ||
"screen_name": "jamesgarcia123", | ||
"lang": "en", | ||
"profile_background_tile": false, | ||
"favourites_count": 0, | ||
"name": "James Garcia", | ||
"url": null, | ||
"created_at": "Sun Nov 21 17:11:16 +0000 2010", | ||
"contributors_enabled": false, | ||
"time_zone": null, | ||
"protected": false, | ||
"following": false, | ||
"listed_count": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Given /^I am on the homepage$/ do | ||
visit '/' | ||
end | ||
|
||
When /^I follow "([^"]*)"$/ do |selector| | ||
click_link selector | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require File.join(File.dirname(__FILE__), '../../app') | ||
|
||
require 'rspec' | ||
require 'rack/test' | ||
require 'webrat' | ||
require 'fakeweb' | ||
|
||
FakeWeb.allow_net_connect = false | ||
|
||
FakeWeb.register_uri( | ||
:post, | ||
'https://api.twitter.com/oauth/request_token', | ||
body: 'oauth_token=fake&oauth_token_secret=fake' | ||
) | ||
|
||
FakeWeb.register_uri( | ||
:post, | ||
'https://api.twitter.com/oauth/access_token', | ||
body: 'oauth_token=fake&oauth_token_secret=fake&user_id=218183011' | ||
) | ||
|
||
FakeWeb.register_uri( | ||
:get, | ||
'https://api.twitter.com/1/account/verify_credentials.json', | ||
body: File.read(File.join(File.dirname(__FILE__), '../fixtures/twitter_user.json')) | ||
) | ||
|
||
Webrat.configure do |config| | ||
config.mode = :rack | ||
end | ||
|
||
module AppWorld | ||
include Rack::Test::Methods | ||
include Webrat::Methods | ||
|
||
def app | ||
Sinatra::Application | ||
end | ||
end | ||
|
||
World(AppWorld) |