facebook_test_users 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in facebook_test_users.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Philotic, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # A gem to ease the pain of managing Facebook test users
2
+
3
+ Testing Facebook apps is hard; part of that difficulty comes from
4
+ managing your test users. Currently, Facebook's "Developer" app
5
+ doesn't offer any way to do it, so you wind up with a bunch of `curl`
6
+ commands and pain.
7
+
8
+ This gem tries to take away the pain of managing your test users. It's
9
+ easy to get started.
10
+
11
+ `$ gem install facebook_test_users`
12
+
13
+ `$ fbtu apps add --name myapp --app-id 123456 --app-secret abcdef`
14
+
15
+ `$ fbtu users list --app myapp`
16
+
17
+ `$ fbtu users add --app myapp`
18
+
19
+ `$ fbtu users rm --app myapp --user 1000000093284356`
20
+
21
+ You can also use it in your own Ruby applications; `require
22
+ "facebook_test_users"` and off you go.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ begin
5
+ require 'rspec/core/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new do |t|
8
+ t.pattern = 'spec/**/*_spec.rb'
9
+ end
10
+
11
+ task :default => :spec
12
+
13
+ rescue LoadError
14
+ nil
15
+ end
data/bin/fbtu ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'facebook_test_users/cli'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'facebook_test_users/cli'
8
+ end
9
+
10
+ FacebookTestUsers::CLI.start
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "facebook_test_users/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "facebook_test_users"
7
+ s.version = FacebookTestUsers::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Sam Merritt"]
10
+ s.email = ["spam@andcheese.org"]
11
+ s.homepage = "https://github.com/smerritt/facebook_test_users"
12
+ s.summary = %q{A CLI tool + library for manipulating Facebook test users}
13
+ s.description =
14
+ "Test users are extremely handy for testing your Facebook applications. This gem " +
15
+ "lets you create and delete users and make them befriend one another. " +
16
+ "It is intended to make testing your Facebook applications slightly less painful."
17
+
18
+ s.rubyforge_project = "facebook_test_users"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+
25
+ s.add_dependency 'rest-client', '~> 1.6.1'
26
+ s.add_dependency 'thor', '~> 0.14.6'
27
+ s.add_dependency 'json_pure', '~> 1.5.0'
28
+
29
+ s.add_development_dependency 'fakeweb', '~>1.3.0'
30
+ s.add_development_dependency 'fakeweb-matcher', '~>1.2.2'
31
+ s.add_development_dependency 'rspec', '~> 2.3.0'
32
+ end
@@ -0,0 +1,33 @@
1
+ require 'cgi'
2
+ require 'restclient'
3
+
4
+ # A million thanks to Filip Tepper for https://github.com/filiptepper/facebook-oauth-example
5
+
6
+ module FacebookTestUsers
7
+ class AccessToken
8
+
9
+ OAUTH_BASE = 'https://graph.facebook.com/oauth/access_token'
10
+
11
+ def self.get(app_id, app_secret, oauth_base=OAUTH_BASE)
12
+ response = RestClient.get(
13
+ oauth_base,
14
+ :params => {
15
+ 'client_id' => app_id,
16
+ 'client_secret' => app_secret,
17
+ 'grant_type' => 'client_credentials' # FB magic string
18
+ })
19
+
20
+ extract_access_token(response)
21
+ end
22
+
23
+ private
24
+
25
+ def self.extract_access_token(response_body)
26
+ response_body.
27
+ match(/=(.*)/). # response is a string like "access_token=bunch-o-crap"
28
+ captures[0].
29
+ strip
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,86 @@
1
+ require 'json'
2
+
3
+ module FacebookTestUsers
4
+ class App
5
+
6
+ attr_reader :name, :id, :secret
7
+
8
+ def initialize(attrs)
9
+ @name, @id, @secret = attrs[:name], attrs[:id], attrs[:secret]
10
+ validate!
11
+ end
12
+
13
+ def attrs
14
+ {:name => name, :id => id, :secret => secret}
15
+ end
16
+
17
+ def self.create!(attrs)
18
+ new_guy = new(attrs)
19
+
20
+ if all.find {|app| app.name == new_guy.name }
21
+ raise ArgumentError, "App names must be unique, and there is already an app named \"#{new_guy.name}\"."
22
+ end
23
+
24
+ DB.update do |data|
25
+ data[:apps] ||= []
26
+ data[:apps] << new_guy.attrs
27
+ end
28
+ end
29
+
30
+ def users
31
+ users_data = RestClient.get(users_url, :params => {
32
+ :access_token => access_token
33
+ })
34
+
35
+ JSON[users_data]["data"].map do |user_data|
36
+ User.new(user_data)
37
+ end
38
+ end
39
+
40
+ def create_user
41
+ user_data = RestClient.post(users_url,
42
+ :access_token => access_token,
43
+ :installed => true)
44
+
45
+ User.new(JSON[user_data])
46
+ end
47
+
48
+ ## query methods
49
+ def self.all
50
+ if DB[:apps]
51
+ DB[:apps].map {|attrs| new(attrs) }
52
+ else
53
+ []
54
+ end
55
+ end
56
+
57
+ def self.find_by_name(name)
58
+ all.find {|a| a.name == name}
59
+ end
60
+
61
+ private
62
+
63
+ def users_url
64
+ GRAPH_API_BASE + "/#{id}/accounts/test-users"
65
+ end
66
+
67
+ def access_token
68
+ @access_token ||= AccessToken.get(id, secret)
69
+ end
70
+
71
+ def validate!
72
+ unless name && name =~ /\S/
73
+ raise ArgumentError, "App name must not be empty"
74
+ end
75
+
76
+ unless id && id =~ /^[0-9a-f]+$/i
77
+ raise ArgumentError, "App id must be a nonempty hex string"
78
+ end
79
+
80
+ unless secret && secret =~ /^[0-9a-f]+$/i
81
+ raise ArgumentError, "App secret must be a nonempty hex string"
82
+ end
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,111 @@
1
+ require 'thor'
2
+ require 'facebook_test_users'
3
+
4
+ module FacebookTestUsers
5
+ class CLI < Thor
6
+ class Apps < Thor
7
+
8
+ check_unknown_options!
9
+ def self.exit_on_failure?() true end
10
+
11
+ default_task :list
12
+
13
+ desc "add", "Tell fbtu about a new application (must already exist on FB)"
14
+ method_option "app_id", :type => :string, :required => true, :banner => "OpenGraph ID of the app"
15
+ method_option "app_secret", :type => :string, :required => true, :banner => "App's secret key"
16
+ method_option "name", :type => :string, :required => true, :banner => "Name of the app (so you don't have to remember its ID)"
17
+ def add
18
+ FacebookTestUsers::App.create!(:name => options[:name], :id => options[:app_id], :secret => options[:app_secret])
19
+ list
20
+ end
21
+
22
+ desc "list", "List the applications fbtu knows about"
23
+ def list
24
+ App.all.each do |app|
25
+ puts "#{app.name} (id: #{app.id})"
26
+ end
27
+ end
28
+
29
+ end # Apps
30
+
31
+ class Users < Thor
32
+ check_unknown_options!
33
+ def self.exit_on_failure?() true end
34
+
35
+ desc "list", "List available test users for an application"
36
+ method_option "app", :aliases => %w[-a], :type => :string, :required => true, :banner => "Name of the app"
37
+
38
+ def list
39
+ app = find_app!(options[:app])
40
+ if app.users.any?
41
+ shell.print_table([
42
+ ['User ID', 'Access Token', 'Login URL'],
43
+ *(app.users.map do |user|
44
+ [user.id, user.access_token, user.login_url]
45
+ end)
46
+ ])
47
+ else
48
+ puts "App #{app.name} has no users."
49
+ end
50
+ end
51
+
52
+ desc "add", "Add a test user to an application"
53
+ method_option "app", :aliases => %w[-a], :type => :string, :required => true, :banner => "Name of the app"
54
+
55
+ def add
56
+ app = find_app!(options[:app])
57
+ user = app.create_user
58
+ puts "User ID: #{user.id}"
59
+ puts "Access Token: #{user.access_token}"
60
+ puts "Login URL: #{user.login_url}"
61
+ end
62
+
63
+ desc "rm", "Remove a test user from an application"
64
+ method_option "app", :aliases => %w[-a], :type => :string, :required => true, :banner => "Name of the app"
65
+ method_option "user", :banner => "ID of the user to remove", :aliases => %w[-u], :type => :string, :required => true
66
+
67
+ def rm
68
+ app = find_app!(options[:app])
69
+ user = app.users.find do |user|
70
+ user.id.to_s == options[:user].to_s
71
+ end
72
+
73
+ if user
74
+ user.destroy
75
+ else
76
+ $stderr.write("Unknown user '#{options[:user]}'")
77
+ raise ArgumentError, "No such user"
78
+ end
79
+ end
80
+
81
+ desc "nuke", "Remove all test users from an application. Use with care."
82
+ method_option "app", :aliases => %w[-a], :type => :string, :required => true, :banner => "Name of the app"
83
+
84
+ def nuke
85
+ app = find_app!(options[:app])
86
+ app.users.each(&:destroy)
87
+ end
88
+
89
+ private
90
+ def find_app!(name)
91
+ app = App.find_by_name(options[:app])
92
+ unless app
93
+ $stderr.puts "Unknown app #{options[:app]}."
94
+ $stderr.puts "Run 'fbtu apps' to see known apps."
95
+ raise ArgumentError, "No such app"
96
+ end
97
+ app
98
+ end
99
+
100
+ end # Users
101
+
102
+ check_unknown_options!
103
+ def self.exit_on_failure?() true end
104
+
105
+ desc "apps", "Commands for managing FB applications"
106
+ subcommand :apps, FacebookTestUsers::CLI::Apps
107
+
108
+ desc "apps", "Commands for managing FB applications' test users"
109
+ subcommand :users, FacebookTestUsers::CLI::Users
110
+ end
111
+ end
@@ -0,0 +1,52 @@
1
+ require 'yaml'
2
+
3
+ module FacebookTestUsers
4
+
5
+ # This is about the dumbest DB you can get. It's a hash that knows
6
+ # how to serialize itself. Dumb, but it gets the job done.
7
+ class DB
8
+ class << self
9
+
10
+ def [](arg)
11
+ # FIXME deep-freeze this; shallow freezing is insufficient
12
+ result = yaml[arg]
13
+ result.freeze
14
+ result
15
+ end
16
+
17
+ def update
18
+ @cached_yaml = nil
19
+ data = _yaml
20
+ yield data
21
+
22
+ # do this *before* blowing away the db
23
+ data_as_yaml = data.to_yaml
24
+ File.open(filename, 'w') { |f| f.write(data_as_yaml) }
25
+ end
26
+
27
+ def filename
28
+ @filename || File.join(ENV['HOME'], '.fbturc')
29
+ end
30
+
31
+ def filename=(f)
32
+ @cached_yaml = nil
33
+ @filename = f
34
+ end
35
+
36
+ private
37
+
38
+ def yaml
39
+ @cached_yaml ||= _yaml
40
+ end
41
+
42
+ def _yaml
43
+ if File.exist?(filename)
44
+ YAML.load_file(filename) || {}
45
+ else
46
+ {}
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,26 @@
1
+ require 'uri'
2
+
3
+ module FacebookTestUsers
4
+ class User
5
+
6
+ attr_reader :id, :access_token, :login_url
7
+
8
+ def initialize(attrs)
9
+ # Hacky, but it allows for use of symbol keys, which are nice in
10
+ # a console.
11
+ @id, @access_token, @login_url = %w[id access_token login_url].map do |field|
12
+ attrs[field.to_s] || attrs[field.to_sym]
13
+ end
14
+ end
15
+
16
+ def destroy
17
+ RestClient.delete(destroy_url)
18
+ end
19
+
20
+ private
21
+
22
+ def destroy_url
23
+ GRAPH_API_BASE + "/#{id}?access_token=#{URI.escape(access_token.to_s)}"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module FacebookTestUsers
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'facebook_test_users/access_token'
2
+ require 'facebook_test_users/app'
3
+ require 'facebook_test_users/db'
4
+ require 'facebook_test_users/user'
5
+
6
+ module FacebookTestUsers
7
+ GRAPH_API_BASE = "https://graph.facebook.com"
8
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
+
3
+ describe "fbtu apps add" do
4
+ it "lets you add an app" do
5
+ fbtu %w[apps add --app-id 123456 --app-secret 7890 --name hydrogen]
6
+
7
+ fbtu %w[apps list]
8
+ @out.should include("hydrogen")
9
+ @out.should_not include("squirrel")
10
+ end
11
+
12
+ it "won't let you add an app with a bogus ID" do
13
+ lambda do
14
+ fbtu %w[apps add --app-id xyzzy --app-secret 7890 --name hydrogen], :quiet => true
15
+ end.should raise_error
16
+ end
17
+
18
+ it "won't let you add an app with a bogus secret" do
19
+ lambda do
20
+ fbtu %w[apps add --app-id 123456 --app-secret xyzzy --name hydrogen], :quiet => true
21
+ end.should raise_error
22
+ end
23
+
24
+ it "won't let you add an app without a name" do
25
+ lambda do
26
+ fbtu %w[apps add --app-id 123456 --app-secret 123456], :quiet => true
27
+ end.should raise_error
28
+ end
29
+
30
+ it "won't let you add an app with a duplicate name" do
31
+ fbtu %w[apps add --app-id 123456 --app-secret 7890 --name hydrogen]
32
+ lambda do
33
+ fbtu %w[apps add --app-id 123456 --app-secret 7890 --name hydrogen], :quiet => true
34
+ end.should raise_error
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
+
3
+ describe "fbtu apps list" do
4
+ it "does not blow up when there's no dotfile" do
5
+ File.unlink @fbtu_dotfile.path
6
+
7
+ lambda do
8
+ fbtu %w[apps list]
9
+ end.should_not raise_error
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ describe "fbtu apps" do
4
+ it "raises an error on baloney" do
5
+ lambda do
6
+ fbtu %w[apps somecrap], :quiet => true
7
+ end.should raise_error
8
+ end
9
+
10
+ it "defaults to listing apps" do
11
+ fbtu %w[apps add --name shlomo --app-id 12345 --app-secret abcdef]
12
+ fbtu %w[apps]
13
+ @out.should include("shlomo")
14
+ @out.should include("12345")
15
+ end
16
+
17
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
+
3
+ describe "fbtu users add" do
4
+ before(:each) do
5
+ fbtu %w[apps add --name alpha --app-id 123456 --app-secret abcdef]
6
+ FakeWeb.register_uri(:get,
7
+ 'https://graph.facebook.com/oauth/access_token?client_id=123456&client_secret=abcdef&grant_type=client_credentials',
8
+ :body => 'access_token=doublesecret')
9
+
10
+ new_user = {
11
+ "id" => 60189,
12
+ "access_token" => 5795927166794,
13
+ "login_url" => "https://facebook.example.com/login/60189",
14
+ }
15
+
16
+ FakeWeb.register_uri(:post,
17
+ 'https://graph.facebook.com/123456/accounts/test-users',
18
+ :body => new_user.to_json)
19
+ end
20
+
21
+ it "adds a user with the app installed" do
22
+ fbtu %w[users add --app alpha]
23
+ @out.should include("60189")
24
+ end
25
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
+
3
+ describe "fbtu users list" do
4
+ before(:each) do
5
+ fbtu %w[apps add --name alpha --app-id 123456 --app-secret abcdef]
6
+ FakeWeb.register_uri(:get,
7
+ 'https://graph.facebook.com/oauth/access_token?client_id=123456&client_secret=abcdef&grant_type=client_credentials',
8
+ :body => 'access_token=doublesecret')
9
+
10
+ user_data = {
11
+ "data" => [{
12
+ "id" => 74040,
13
+ "access_token" => 4992011197,
14
+ "login_url" => "https://facebook.example.com/login/74040",
15
+ }, {
16
+ "id" => 78767,
17
+ "access_token" => 9178342034,
18
+ "login_url" => "https://facebook.example.com/login/78767",
19
+ }]
20
+ }
21
+
22
+ FakeWeb.register_uri(:get,
23
+ 'https://graph.facebook.com/123456/accounts/test-users?access_token=doublesecret',
24
+ :body => user_data.to_json)
25
+
26
+ end
27
+
28
+ it "lists available users" do
29
+ fbtu %w[users list --app alpha]
30
+ @out.should include("74040")
31
+ @out.should include("https://facebook.example.com/login/74040")
32
+
33
+ @out.should include("78767")
34
+ end
35
+
36
+ it "does something reasonable when the app doesn't exist" do
37
+ lambda do
38
+ fbtu %w[users list --app omega], :quiet => true
39
+ end.should raise_error
40
+ @err.should include("Unknown app")
41
+ end
42
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
+
3
+ describe "fbtu users nuke" do
4
+ before(:each) do
5
+ fbtu %w[apps add --name alpha --app-id 123456 --app-secret abcdef]
6
+ FakeWeb.register_uri(:get,
7
+ 'https://graph.facebook.com/oauth/access_token?client_id=123456&client_secret=abcdef&grant_type=client_credentials',
8
+ :body => 'access_token=doublesecret')
9
+
10
+ user1 = {
11
+ "id" => 21055,
12
+ "access_token" => 9494864868,
13
+ "login_url" => "https://facebook.example.com/log_this_guy_in?who=thatguy",
14
+ }
15
+ user2 = {
16
+ "id" => 11442,
17
+ "access_token" => 5688139914,
18
+ "login_url" => "https://facebook.example.com/log_this_guy_in?who=thatguy",
19
+ }
20
+
21
+ FakeWeb.register_uri(:get,
22
+ 'https://graph.facebook.com/123456/accounts/test-users?access_token=doublesecret',
23
+ :body => {:data => [user1, user2]}.to_json)
24
+ end
25
+
26
+ it "deletes all the users" do
27
+ FakeWeb.register_uri(:delete,
28
+ "https://graph.facebook.com/21055?access_token=9494864868",
29
+ :body => "true")
30
+ FakeWeb.register_uri(:delete,
31
+ "https://graph.facebook.com/11442?access_token=5688139914",
32
+ :body => "true")
33
+
34
+ fbtu %w[users nuke --app alpha]
35
+
36
+ FakeWeb.should have_requested(:delete,
37
+ "https://graph.facebook.com/21055?access_token=9494864868")
38
+ FakeWeb.should have_requested(:delete,
39
+ "https://graph.facebook.com/11442?access_token=5688139914")
40
+ end
41
+ end
@@ -0,0 +1,38 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
+
3
+ describe "fbtu users rm" do
4
+ before(:each) do
5
+ fbtu %w[apps add --name alpha --app-id 123456 --app-secret abcdef]
6
+ FakeWeb.register_uri(:get,
7
+ 'https://graph.facebook.com/oauth/access_token?client_id=123456&client_secret=abcdef&grant_type=client_credentials',
8
+ :body => 'access_token=doublesecret')
9
+
10
+ user = {
11
+ "id" => 21055,
12
+ "access_token" => 9494864868,
13
+ "login_url" => "https://facebook.example.com/log_this_guy_in?who=thatguy",
14
+ }
15
+
16
+ FakeWeb.register_uri(:get,
17
+ 'https://graph.facebook.com/123456/accounts/test-users?access_token=doublesecret',
18
+ :body => {:data => [user]}.to_json)
19
+ end
20
+
21
+ it "deletes the user" do
22
+ FakeWeb.register_uri(:delete,
23
+ "https://graph.facebook.com/21055?access_token=9494864868",
24
+ :body => "true")
25
+
26
+ fbtu %w[users rm --app alpha --user 21055]
27
+
28
+ FakeWeb.should have_requested(:delete,
29
+ "https://graph.facebook.com/21055?access_token=9494864868")
30
+ end
31
+
32
+ it "tells you if there was no such user" do
33
+ lambda do
34
+ fbtu %w[users rm --app alpha --user bogus], :quiet => true
35
+ end.should raise_error
36
+ @err.should include("Unknown user")
37
+ end
38
+ end
@@ -0,0 +1,77 @@
1
+ require 'pp'
2
+ require 'stringio'
3
+ require 'tempfile'
4
+
5
+ require 'facebook_test_users'
6
+ require 'facebook_test_users/cli'
7
+
8
+ require 'fakeweb'
9
+ require 'fakeweb_matcher'
10
+
11
+ module FBTU
12
+ module SpecHelpers
13
+ module SemanticNames
14
+
15
+ def given(name)
16
+ it_should_behave_like(name)
17
+ end
18
+
19
+ end
20
+
21
+ module CliTestMethods
22
+ def fbtu(argv_ish, options={})
23
+ @out = StringIO.new
24
+ @err = StringIO.new
25
+
26
+ begin
27
+ capture_stdout_into(@out) do
28
+ capture_stderr_into(@err) do
29
+ FacebookTestUsers::CLI.start(argv_ish)
30
+ end
31
+ end
32
+ rescue Exception => e
33
+ unless options[:quiet]
34
+ puts "Something failed.\nArgs:%s\nstdout:\n%s\n\nstderr:\n%s\n" % [
35
+ argv_ish.inspect,
36
+ @out.string,
37
+ @err.string
38
+ ]
39
+ end
40
+ raise e # always propagate failure up the stack
41
+ ensure
42
+ @out = @out.string
43
+ @err = @err.string
44
+ end
45
+ end
46
+
47
+ def capture_stdout_into(io)
48
+ $stdout = io
49
+ yield
50
+ ensure
51
+ $stdout = STDOUT
52
+ end
53
+
54
+ def capture_stderr_into(io)
55
+ $stderr = io
56
+ yield
57
+ ensure
58
+ $stderr = STDERR
59
+ end
60
+
61
+ end # CliTestMethods
62
+
63
+ end
64
+ end
65
+
66
+ RSpec.configure do |config|
67
+ config.include FBTU::SpecHelpers::CliTestMethods
68
+ config.extend FBTU::SpecHelpers::SemanticNames
69
+
70
+ config.before(:each) do
71
+ @fbtu_dotfile = Tempfile.new('fbtu-prefs')
72
+ FacebookTestUsers::DB.filename = @fbtu_dotfile.path
73
+ end
74
+
75
+ config.before(:all) { FakeWeb.allow_net_connect = false }
76
+
77
+ end
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: facebook_test_users
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Sam Merritt
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-10 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rest-client
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 6
33
+ - 1
34
+ version: 1.6.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: thor
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 43
46
+ segments:
47
+ - 0
48
+ - 14
49
+ - 6
50
+ version: 0.14.6
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: json_pure
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 1
64
+ - 5
65
+ - 0
66
+ version: 1.5.0
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: fakeweb
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 27
78
+ segments:
79
+ - 1
80
+ - 3
81
+ - 0
82
+ version: 1.3.0
83
+ type: :development
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: fakeweb-matcher
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ hash: 27
94
+ segments:
95
+ - 1
96
+ - 2
97
+ - 2
98
+ version: 1.2.2
99
+ type: :development
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: rspec
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 2
112
+ - 3
113
+ - 0
114
+ version: 2.3.0
115
+ type: :development
116
+ version_requirements: *id006
117
+ description: Test users are extremely handy for testing your Facebook applications. This gem lets you create and delete users and make them befriend one another. It is intended to make testing your Facebook applications slightly less painful.
118
+ email:
119
+ - spam@andcheese.org
120
+ executables:
121
+ - fbtu
122
+ extensions: []
123
+
124
+ extra_rdoc_files: []
125
+
126
+ files:
127
+ - .gitignore
128
+ - Gemfile
129
+ - LICENSE
130
+ - README.md
131
+ - Rakefile
132
+ - bin/fbtu
133
+ - facebook_test_users.gemspec
134
+ - lib/facebook_test_users.rb
135
+ - lib/facebook_test_users/access_token.rb
136
+ - lib/facebook_test_users/app.rb
137
+ - lib/facebook_test_users/cli.rb
138
+ - lib/facebook_test_users/db.rb
139
+ - lib/facebook_test_users/user.rb
140
+ - lib/facebook_test_users/version.rb
141
+ - spec/fbtu/apps/add_spec.rb
142
+ - spec/fbtu/apps/list_spec.rb
143
+ - spec/fbtu/apps_spec.rb
144
+ - spec/fbtu/users/add_spec.rb
145
+ - spec/fbtu/users/list_spec.rb
146
+ - spec/fbtu/users/nuke_spec.rb
147
+ - spec/fbtu/users/rm_spec.rb
148
+ - spec/spec_helper.rb
149
+ has_rdoc: true
150
+ homepage: https://github.com/smerritt/facebook_test_users
151
+ licenses: []
152
+
153
+ post_install_message:
154
+ rdoc_options: []
155
+
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ hash: 3
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
175
+ version: "0"
176
+ requirements: []
177
+
178
+ rubyforge_project: facebook_test_users
179
+ rubygems_version: 1.3.7
180
+ signing_key:
181
+ specification_version: 3
182
+ summary: A CLI tool + library for manipulating Facebook test users
183
+ test_files:
184
+ - spec/fbtu/apps/add_spec.rb
185
+ - spec/fbtu/apps/list_spec.rb
186
+ - spec/fbtu/apps_spec.rb
187
+ - spec/fbtu/users/add_spec.rb
188
+ - spec/fbtu/users/list_spec.rb
189
+ - spec/fbtu/users/nuke_spec.rb
190
+ - spec/fbtu/users/rm_spec.rb
191
+ - spec/spec_helper.rb