capybara-facebook-macros 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 35765f7f46896149a24a44bc8ebcf71ef37c5468
4
+ data.tar.gz: b66b74b2451c968b9b9ad9095b2abe92b0f4a56e
5
+ SHA512:
6
+ metadata.gz: 88f1a14e49bc4cc03f6ffd563cd7667d84cf5d9cfeb7fde479dbb0b942b16687055fe56c1cd3b4ccfc80b677512755a6c1f1cd966cf0abc69909fcf45789e09a
7
+ data.tar.gz: a68af5e1c67bf2a5229b971bf43c65f7d8bd3a10d9a96c8625602e7b37f52a593d4a642a4bcc31e672bf1300460be7c7f6445c25c613e30d2760b2fe4e9a7f12
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capybara-facebook-macros.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jordan Rogers-Smith
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ # Capybara Facebook Macros
2
+
3
+ Adds a few convenient methods to capybaras DSL for interacting with Facebook. Using the credentials of a Facebook test user associated with your facebook app the gem provides methods for logging in, accepting read and write permissions, logging out and deauthing the app
4
+
5
+ They have been used and tested against selenium and capybara webkit drivers running locally as well as capybara-webkit running against a Xvfb headless server on Jenkins.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'capybara-facebook-macros'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install capybara-facebook-macros
20
+
21
+ ## Usage
22
+
23
+ Within a capybara feature:
24
+
25
+ # given a css selector that triggers the auth dialogue, login and accept.
26
+
27
+ complete_facebook_dialogues_on_click('#login', {:email => testuser@fb.com , :password => 1234})
28
+
29
+ # email/password can be a hash or any class that has the attributes email, password ie test_user
30
+ # has test_user.email and test_user.password
31
+
32
+ complete_facebook_dialogues_on_click('#login', test_user)
33
+
34
+ # logout og facebook
35
+
36
+ logout
37
+
38
+ # if interacting with the page asks for additional permision ie facebok photos when choosing a picture
39
+ # handle the additional flow. Works for both read and write.
40
+
41
+ accept_additional_permissions
42
+
43
+ # remove the app permission
44
+
45
+ deauth_app
46
+
47
+ ## TODO
48
+
49
+ - Tests
50
+
51
+ ## Contributing
52
+
53
+ Any problems log them on the issues tracker or submit a pull request and passing tests
54
+
55
+ 1. Fork it
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capybara-facebook-macros/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "capybara-facebook-macros"
8
+ gem.version = Capybara::Facebook::Macros::VERSION
9
+ gem.authors = ["Jordan Rogers-Smith"]
10
+ gem.email = ["jordan.rogers-smith@betapond.com"]
11
+ gem.description = %q{Adds a couple of convenient macros for working with facebook in capybara}
12
+ gem.summary = %q{Adds a couple of convenient macros for working with facebook in capybara}
13
+ gem.homepage = "https://github.com/jordanrs/capybara-facebook-macros"
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ if RUBY_VERSION < "1.9"
22
+ gem.add_dependency 'capybara', ['>= 1.0', '< 2']
23
+ else
24
+ gem.add_dependency 'capybara', ['>= 1.0', '< 3']
25
+ end
26
+
27
+ gem.add_development_dependency 'rspec', '~> 2.7'
28
+ end
@@ -0,0 +1,4 @@
1
+ require "capybara-facebook-macros/version"
2
+ require "capybara/dsl"
3
+ require "capybara-facebook-macros/macros"
4
+
@@ -0,0 +1,82 @@
1
+ module Capybara
2
+ module DSL
3
+
4
+ def complete_facebook_dialogues_on_click(element, test_user)
5
+ # until bookface version bumped to latest we have no way to know its ready so delay, not ideal
6
+ sleep 2
7
+ find("#{element}").click
8
+ return if page.driver.browser.window_handles.length == 1
9
+ within_window page.driver.browser.window_handles.last do
10
+ fill_in_facebook_form(test_user) if page.has_css?('#loginbutton')
11
+ accept_permissions_outside_facebook
12
+ end
13
+ end
14
+
15
+ def login_and_authorise_app_outside_facebook(test_user)
16
+ within_window('Facebook') do
17
+ fill_in_facebook_form(test_user) if page.has_css?('#loginbutton')
18
+ accept_permissions_outside_facebook
19
+ end
20
+ end
21
+
22
+ def accept_additional_permissions
23
+ return if page.driver.browser.window_handles.length == 1
24
+ within_window page.driver.browser.window_handles.last do
25
+ accept_permissions_outside_facebook
26
+ end
27
+ end
28
+
29
+ def accept_permissions_outside_facebook
30
+ # these checks are required as the flow cna change depending on if the user has authed before
31
+ # read permissions dialogue
32
+ # click_on('OK') if page.driver.browser.window_handles.length == 2
33
+ if page.driver.browser.window_handles.length >= 2
34
+ read_perms = first(:xpath, "//button[@name='__CONFIRM__']")
35
+ read_perms.click unless read_perms.nil?
36
+ end
37
+
38
+ if page.driver.browser.window_handles.length >= 2
39
+ write_perms = first(:xpath, "//button[@name='__CONFIRM__']")
40
+ write_perms.click unless write_perms.nil?
41
+ end
42
+
43
+ # write permision dialogue
44
+ # click_on('OK') if page.driver.browser.window_handles.length == 2
45
+ end
46
+
47
+ def login_to_facebook_homepage(test_user, after_login_url)
48
+ fill_in_facebook_form(test_user)
49
+ visit after_login_url
50
+ end
51
+
52
+ def deauth_app
53
+ sleep 1
54
+ page.execute_script %Q{
55
+ FB.api("/me/permissions","DELETE", function(response){
56
+ console.log(response)
57
+ });
58
+ }
59
+ sleep 1
60
+ end
61
+
62
+ def logout
63
+ sleep 1
64
+ page.execute_script %Q{
65
+ FB.logout(function(response) {
66
+ // user is now logged out
67
+ });
68
+ }
69
+ sleep 1
70
+ end
71
+
72
+ def fill_in_facebook_form(test_user)
73
+ if test_user.class == Hash
74
+ test_user = OpenStruct.new test_user
75
+ end
76
+
77
+ fill_in('email', :with => "#{test_user.email}")
78
+ fill_in('pass', :with => "#{test_user.password}")
79
+ find('#loginbutton').click
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,7 @@
1
+ module Capybara
2
+ module Facebook
3
+ module Macros
4
+ VERSION = "0.1"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-facebook-macros
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Jordan Rogers-Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '2.7'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '2.7'
47
+ description: Adds a couple of convenient macros for working with facebook in capybara
48
+ email:
49
+ - jordan.rogers-smith@betapond.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - capybara-facebook-macros.gemspec
60
+ - lib/capybara-facebook-macros.rb
61
+ - lib/capybara-facebook-macros/macros.rb
62
+ - lib/capybara-facebook-macros/version.rb
63
+ homepage: https://github.com/jordanrs/capybara-facebook-macros
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.1.4
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Adds a couple of convenient macros for working with facebook in capybara
87
+ test_files: []