sauce-cucumber 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -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/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Sauce::Cucumber
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sauce-cucumber'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sauce-cucumber
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,122 @@
1
+ require 'capybara'
2
+ require 'cucumber'
3
+ require 'sauce/job'
4
+ require 'sauce/capybara'
5
+
6
+ module Sauce
7
+ module Capybara
8
+ module Cucumber
9
+ def use_sauce_driver
10
+ ::Capybara.current_driver = :sauce
11
+ end
12
+ module_function :use_sauce_driver
13
+
14
+ def name_from_scenario(scenario)
15
+ # Special behavior to handle Scenario Outlines
16
+ if scenario.instance_of? ::Cucumber::Ast::OutlineTable::ExampleRow
17
+ table = scenario.instance_variable_get(:@table)
18
+ outline = table.instance_variable_get(:@scenario_outline)
19
+ return "#{outline.feature.file} - #{outline.title} - #{table.headers} -> #{scenario.name}"
20
+ end
21
+ scenario, feature = _scenario_and_feature_name(scenario)
22
+ return "#{feature} - #{scenario}"
23
+ end
24
+ module_function :name_from_scenario
25
+
26
+ def jenkins_name_from_scenario(scenario)
27
+ # Special behavior to handle Scenario Outlines
28
+ if scenario.instance_of? ::Cucumber::Ast::OutlineTable::ExampleRow
29
+ table = scenario.instance_variable_get(:@table)
30
+ outline = table.instance_variable_get(:@scenario_outline)
31
+ return "#{outline.feature.short_name}.#{outline.title}.#{outline.title} (outline example: #{scenario.name})"
32
+ end
33
+ scenario, feature = _scenario_and_feature_name(scenario)
34
+ return "#{feature}.#{scenario}.#{scenario}"
35
+ end
36
+ module_function :jenkins_name_from_scenario
37
+
38
+ def _scenario_and_feature_name(scenario)
39
+ scenario_name = scenario.name.split("\n").first
40
+ feature_name = scenario.feature.short_name
41
+ return scenario_name, feature_name
42
+ end
43
+ module_function :_scenario_and_feature_name
44
+
45
+ def before_hook
46
+ Sauce::Capybara::Cucumber.use_sauce_driver
47
+ end
48
+ module_function :before_hook
49
+
50
+ def using_jenkins?
51
+ # JENKINS_SERVER_COOKIE seems to be as good as any sentinel value to
52
+ # determine whether we're running under Jenkins or not.
53
+ ENV['JENKINS_SERVER_COOKIE']
54
+ end
55
+ module_function :using_jenkins?
56
+
57
+ def around_hook(scenario, block)
58
+ ::Capybara.current_driver = :sauce
59
+ driver = ::Capybara.current_session.driver
60
+ # This session_id is the job ID used by Sauce Labs, we're pulling it
61
+ # off of the driver now to make sure we have it after `block.call`
62
+ session_id = driver.browser.session_id
63
+ job_name = Sauce::Capybara::Cucumber.name_from_scenario(scenario)
64
+ custom_data = {}
65
+
66
+ if using_jenkins?
67
+ custom_data.merge!({:commit => ENV['GIT_COMMIT'] || ENV['SVN_COMMIT'],
68
+ :jenkins_node => ENV['NODE_NAME'],
69
+ :jenkins_job => ENV['JOB_NAME']})
70
+ end
71
+
72
+ job = Sauce::Job.new('id' => session_id,
73
+ 'name' => job_name,
74
+ 'custom-data' => custom_data)
75
+ job.save unless job.nil?
76
+
77
+ Sauce.config do |c|
78
+ c[:name] = Sauce::Capybara::Cucumber.name_from_scenario(scenario)
79
+ end
80
+
81
+ if using_jenkins?
82
+ # If we're running under Jenkins, we should dump the
83
+ # `SauceOnDemandSessionID` into the Console Output for the Sauce OnDemand
84
+ # Jenkins plugin.
85
+ # See: <https://github.com/saucelabs/sauce_ruby/issues/48>
86
+ output = []
87
+ output << "\nSauceOnDemandSessionID=#{session_id}"
88
+ # The duplication in the scenario_name comes from the fact that the
89
+ # JUnit formatter seems to do the same, so in order to get the sauce
90
+ # OnDemand plugin for Jenkins to co-operate, we need to double it up as
91
+ # well
92
+ output << "job-name=#{Sauce::Capybara::Cucumber.jenkins_name_from_scenario(scenario)}"
93
+ puts output.join(' ')
94
+ end
95
+
96
+ block.call
97
+
98
+ # Quit the driver to allow for the generation of a new session_id
99
+ driver.browser.quit
100
+ driver.instance_variable_set(:@browser, nil)
101
+
102
+ unless job.nil?
103
+ job.passed = !scenario.failed?
104
+ job.save
105
+ end
106
+ end
107
+ module_function :around_hook
108
+ end
109
+ end
110
+ end
111
+
112
+
113
+ begin
114
+ Before('@selenium') do
115
+ Sauce::Capybara::Cucumber.before_hook
116
+ end
117
+
118
+ Around('@selenium') do |scenario, block|
119
+ Sauce::Capybara::Cucumber.around_hook(scenario, block)
120
+ end
121
+ rescue NoMethodError # This makes me sad
122
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../lib/sauce/version')
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["R. Tyler Croy"]
6
+ gem.email = ["tyler@monkeypox.org"]
7
+ gem.description = ''
8
+ gem.summary = ''
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "sauce-cucumber"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = "#{Sauce::MAJOR_VERSION}.0"
17
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sauce-cucumber
3
+ version: !ruby/object:Gem::Version
4
+ hash: 11
5
+ prerelease:
6
+ segments:
7
+ - 2
8
+ - 1
9
+ - 0
10
+ version: 2.1.0
11
+ platform: ruby
12
+ authors:
13
+ - R. Tyler Croy
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-08-15 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: ""
22
+ email:
23
+ - tyler@monkeypox.org
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - README.md
33
+ - Rakefile
34
+ - lib/sauce/cucumber.rb
35
+ - sauce-cucumber.gemspec
36
+ homepage: ""
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.10
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: ""
69
+ test_files: []
70
+