Skip to content

Instantly share code, notes, and snippets.

@mchung
Created December 3, 2010 20:59
Show Gist options
  • Save mchung/727548 to your computer and use it in GitHub Desktop.
Save mchung/727548 to your computer and use it in GitHub Desktop.
module FakewebHelpers
# Make sure nothing gets out (IMPORTANT)
FakeWeb.allow_net_connect = false
# Turns a fixture file name into a full path
def fixture_file(filename)
return '' if filename == ''
File.expand_path(Rails.root.to_s + '/features/fixtures/' + filename)
end
# Convenience methods for stubbing URLs to fixtures
def stub_get(url, filename)
FakeWeb.register_uri(:get, url, :response => fixture_file(filename))
end
def stub_post(url, filename)
FakeWeb.register_uri(:post, url, :response => fixture_file(filename))
end
def stub_any(url, filename)
FakeWeb.register_uri(:any, url, :response => fixture_file(filename))
end
end
World(FakewebHelpers)
Feature: Sign in
In order to get access to protected sections of the site
A user
Should be able to sign in
Scenario: User logs in successfully using Twitter Oauth
Given no user exists with a Twitter account of "heisenthought"
And I sign in from Twitter with the user "heisenthought" # This is the money step!
Then I should be on the home page
When I go to the contests page
Then I should see "Hello, heisenthought!"
When /^I sign in from Twitter with the user "([^"]*)"$/ do |login|
stub_post('https://api.twitter.com/oauth/request_token', 'request_token')
stub_post('https://api.twitter.com/oauth/access_token', 'access_token')
stub_get('https://api.twitter.com/1/account/verify_credentials.json', "verify_#{login}_credentials.json")
visit "/auth/twitter"
visit "/auth/twitter/callback"
store_model("user", login, User.with_login(login)) # pickle
end
HTTP/1.1 200 OK
oauth_token=8ld9IZyxQeVrFZXFDOZH5tAwj6vzJYuLQpl0WUEYtWXc&oauth_token_secret=x6qpRnlEmW9zJbQn4PQVVeVG8KZLPEx6A0TOebgwcuA&oauth_callback_confirmed=true
HTTP/1.1 200 OK
{
"profile_sidebar_fill_color": "0e1621",
"profile_background_tile": false,
"name": "Marc Chung",
"profile_sidebar_border_color": "454b52",
"profile_image_url": "http:\/\/a3.twimg.com\/profile_images\/768477835\/me-linkedin-30a16c5_normal.jpg",
"location": "Arizona",
"created_at": "Wed Aug 20 04:23:31 +0000 2008",
"id_str": "15913931",
"profile_link_color": "cb9934",
"follow_request_sent": false,
"contributors_enabled": false,
"url": "http:\/\/marcchung.com",
"favourites_count": 285,
"utc_offset": -25200,
"id": 15913931,
"profile_use_background_image": true,
"listed_count": 84,
"followers_count": 799,
"protected": false,
"profile_text_color": "575e61",
"lang": "en",
"geo_enabled": false,
"profile_background_color": "181c1f",
"notifications": false,
"time_zone": "Arizona",
"verified": false,
"description": "Woohoo. I'm getting married.",
"friends_count": 599,
"profile_background_image_url": "http:\/\/a3.twimg.com\/profile_background_images\/96118017\/tcchalk_578_9428.jpg",
"statuses_count": 3343,
"status": {
"coordinates": null,
"favorited": false,
"truncated": false,
"created_at": "Sun Oct 31 06:09:04 +0000 2010",
"id_str": "29252665233",
"in_reply_to_user_id_str": "637113",
"text": "@RobotDeathSquad HEISENTHOUGHT ANGRY AT CEREMONY WITH TESTING OAUTH",
"contributors": null,
"id": 29252665233,
"in_reply_to_status_id_str": "29251616538",
"retweet_count": null,
"geo": null,
"retweeted": false,
"in_reply_to_user_id": 637113,
"source": "web",
"in_reply_to_screen_name": "RobotDeathSquad",
"place": null,
"in_reply_to_status_id": 29251616538
},
"following": false,
"show_all_inline_media": false,
"screen_name": "heisenthought"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment