cucumber-rapid7 0.0.1.beta.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 905198412fc25706ec71608451bbe265e9cf6cb8
4
+ data.tar.gz: 829fc1c439736c6f9fa9a235458dbfb84880fd7f
5
+ SHA512:
6
+ metadata.gz: b54567750084877b42d95c3fb67298b8422b6b81f23976d2ad010fdcb6a0d0e12a04ddac5135f335401243173fa5f584be1168917579a566db6897750ef7f172
7
+ data.tar.gz: ec8f08ac7ab2fd11fef82223aa675fb202621f9b1e7b1c03c51dc9def1427aa215392e79ebb4ccb00eaa952e626df3369d101b11e944036adc4a2fc64ab0a792
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/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Erran Carey <erran_carey@rapid7.com>
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Cucumber::Rapid7
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cucumber-rapid7'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cucumber-rapid7
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 'Add 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 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cucumber/rapid7/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cucumber-rapid7'
8
+ spec.version = Cucumber::Rapid7::VERSION
9
+ spec.authors = ['Erran Carey']
10
+ spec.email = ['erran_carey@rapid7.com']
11
+ spec.description = %q{Cucumber extensions used at Rapid7}
12
+ spec.summary = %q{Cucumber extensions for Rapid7}
13
+ spec.homepage = 'https://github.com/ecarey-r7/cucumber-rapid7'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ end
@@ -0,0 +1,54 @@
1
+ require 'cucumber/ast/outline_table/example_row'
2
+ require 'cucumber/ast/scenario'
3
+ require 'cucumber/term/ansicolor'
4
+
5
+ module Cucumber
6
+ module Rapid7
7
+ module Auxiliary
8
+ def find_scenario_name(scenario_or_outline)
9
+ case scenario_or_outline
10
+ when Cucumber::Ast::Scenario
11
+ scenario_or_outline.name
12
+ when Cucumber::Ast::OutlineTable::ExampleRow
13
+ scenario_or_outline.scenario_outline.name
14
+ end
15
+ end
16
+
17
+ def find_file_colon_line(scenario_or_outline)
18
+ case scenario_or_outline
19
+ when Cucumber::Ast::Scenario
20
+ scenario_or_outline.file_colon_line
21
+ when Cucumber::Ast::OutlineTable::ExampleRow
22
+ scenario_or_outline.scenario_outline.file_colon_line
23
+ end
24
+ end
25
+
26
+ def example_row_from_scenario(scenario)
27
+ if scenario.is_a? Cucumber::Ast::OutlineTable::ExampleRow
28
+ example_row = [
29
+ scenario.name.split('|').map { |column| column.cyan }.join(' | '.reset),
30
+ ' |'.reset
31
+ ].flatten.join.sub('| ', '')
32
+ end
33
+
34
+ if example_row && ENV['CI']
35
+ Cucumber::Term::ANSIColor.uncolored(example_row)
36
+ elsif example_row
37
+ example_row
38
+ end
39
+ end
40
+
41
+ def skip_tag_error(scenario_name, common_tags, example_row = false)
42
+ skip_error = [
43
+ ' Skipping'.cyan,
44
+ %("#{scenario_name}").bold.cyan,
45
+ 'due to having the following auto-skip tags:'.cyan,
46
+ common_tags.to_s.bold.cyan
47
+ ].join(' ')
48
+
49
+ skip_error << ' |'.reset if example_row
50
+ ENV['CI'] ? Cucumber::Term::ANSIColor.uncolored(skip_error) : skip_error
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,34 @@
1
+ require 'cucumber/formatter/html'
2
+
3
+ class HtmlPostponed < Cucumber::Formatter::Html
4
+ def after_features(features)
5
+ @builder << '</div>' # Close the previous <div>
6
+ @skip_tags = ENV['CUCUMBER_SKIP_TAGS'].split(',')
7
+ @file_colon_lines = []
8
+
9
+ @builder << '<div class="cucumber">'
10
+ @builder << '<div class="feature">'
11
+ @builder << '<h2>'
12
+ @builder << 'Postponed tests (using $CUCUMBER_SKIP_TAGS)'
13
+ @builder << '</h2>'
14
+ @builder << '<span class="tag">'
15
+ @skip_tags.each { |tag| @builder << tag }
16
+ @builder << '</span>'
17
+ @builder << '<ol>'
18
+ features.each do |feature|
19
+ if (@skip_tags & feature.source_tag_names).any?
20
+ unless @file_colon_lines.include? feature.file_colon_line
21
+ @builder << '<li>'
22
+ @builder << feature.file_colon_line
23
+ @builder << '</li>'
24
+ end
25
+ end
26
+ end
27
+ @builder << '</ol>'
28
+ @builder << '</div>'
29
+ @builder << '</div>'
30
+
31
+ @builder << '<div>'
32
+ super # Give the HTML formatter control
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ require 'cucumber/formatter/pretty'
2
+ require 'cucumber/jira'
3
+
4
+ # This formatter is a WIP that will eventually gather information from JIRA
5
+ # based on JIRA themes and Gherkin tags and add the information into cucumber
6
+ # reports.
7
+ #
8
+ # @author Erran Carey <erran_carey@rapid7.com>
9
+ # @api private
10
+ class JiraMetrics < Cucumber::Formatter::Pretty
11
+ def initialize(runtime, path_or_io, options)
12
+ super
13
+
14
+ jira_client = Cucumber::Jira::Soap.new(ENV['JIRA_ENDPOINT'])
15
+ jira_client.login(ENV['JIRA_USER'], ENV['JIRA_PASSWORD'], true)
16
+ @jira_issues = jira_client.search :project => ENV['JIRA_PROJECT_KEY'], :themes => ENV['JIRA_THEMES'].to_s.split(/,\s*/, '')
17
+ end
18
+
19
+ def before_feature(feature)
20
+ super
21
+
22
+ tags = feature.source_tags.map { |tag| tag.name.sub(/^@/, '') }
23
+ jira_tags = tags.grep(/^COSMO-\d+/)
24
+
25
+ issues = @jira_issues.find_all { |issue| jira_tags.include?(issue[:key]) }
26
+
27
+ puts issues
28
+ end
29
+ end
@@ -0,0 +1,135 @@
1
+ require 'cucumber/formatter/duration'
2
+ require 'cucumber/formatter/io'
3
+ require 'terminal-notifier'
4
+
5
+ # A Cucumber formatter that notifies a user through Mac OS X's notification
6
+ # center when the cucumber tests have finished running.
7
+ #
8
+ # @note This formatter was originally written by Jon Frisby (@MrJoy)
9
+ # https://github.com/MrJoy/cucumber-nc
10
+ # @note This formatter incorporates patches from ipwnstuff/cucumber-nc
11
+ # (ipwnstuff => Erran Carey)
12
+ # @author John Frisby <jfrisby@mrjoy.com>
13
+ # @author Erran Carey <erran_carey@rapid7.com>
14
+ # @api private
15
+ class NotificationCenterFormatter
16
+ include Cucumber::Formatter::Duration
17
+ include Cucumber::Formatter::Io
18
+
19
+ attr_reader :step_mother
20
+ def initialize(step_mother, path_or_io, options)
21
+ @step_mother, @options = step_mother, options
22
+ end
23
+
24
+ def after_features(features)
25
+ print_summary(features)
26
+ end
27
+
28
+ def before_feature(feature); end
29
+ def comment_line(comment_line); end
30
+ def after_tags(tags); end
31
+ def tag_name(tag_name); end
32
+ def feature_name(keyword, name); end
33
+ def before_feature_element(feature_element); end
34
+ def after_feature_element(feature_element); end
35
+ def before_background(background); end
36
+ def after_background(background); end
37
+ def background_name(keyword, name, file_colon_line, source_indent); end
38
+ def before_examples_array(examples_array); end
39
+ def examples_name(keyword, name); end
40
+ def before_outline_table(outline_table); end
41
+ def after_outline_table(outline_table); end
42
+ def scenario_name(keyword, name, file_colon_line, source_indent); end
43
+ def before_step(step); end
44
+ def before_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line); end
45
+ def step_name(keyword, step_match, status, source_indent, background, file_colon_line); end
46
+ def doc_string(string); end
47
+ def exception(exception, status); end
48
+ def before_multiline_arg(multiline_arg); end
49
+ def after_multiline_arg(multiline_arg); end
50
+ def before_table_row(table_row); end
51
+ def after_table_row(table_row); end
52
+ def after_table_cell(cell); end
53
+ def table_cell_value(value, status); end
54
+
55
+ private
56
+
57
+ def pluralize(num, str)
58
+ (num == 1) ? str : "#{str}s"
59
+ end
60
+
61
+ def summary_line(features)
62
+ scenarios = step_mother.scenarios.count
63
+ scenarios_failed = step_mother.scenarios(:failed).count
64
+ scenarios_undefined = step_mother.scenarios(:undefined).count
65
+ scenarios_pending = step_mother.scenarios(:pending).count
66
+ scenarios_passing = step_mother.scenarios(:passed).count
67
+
68
+ steps = step_mother.steps.count
69
+ steps_failed = step_mother.steps(:failed).count
70
+ steps_skipped = step_mother.steps(:skipped).count
71
+ steps_undefined = step_mother.steps(:undefined).count
72
+ steps_pending = step_mother.steps(:pending).count
73
+ steps_passing = step_mother.steps(:passed).count
74
+
75
+ counts = []
76
+ counts << "#{scenarios_undefined} undefined" if scenarios_undefined > 0
77
+ counts << "#{scenarios_pending} pending" if scenarios_pending > 0
78
+ counts << "#{scenarios_failed} failed" if scenarios_failed > 0
79
+ counts << "#{scenarios_passing} passed" if scenarios_passing > 0
80
+
81
+ # 5 scenarios (1 undefined, 3 pending, 1 passed)
82
+ case counts.count
83
+ when 4
84
+ summary = "#{scenarios} #{pluralize(scenarios, "scenario")} (#{counts[0]}, #{counts[1]}, #{counts[2]},\n#{counts[3]})\n"
85
+ else
86
+ summary = "#{scenarios} #{pluralize(scenarios, "scenario")} (#{counts.join(', ')})\n"
87
+ end
88
+
89
+ counts = []
90
+ counts << "#{steps_undefined} undefined" if steps_undefined > 0
91
+ counts << "#{steps_skipped} skipped" if steps_skipped > 0
92
+ counts << "#{steps_pending} pending" if steps_pending > 0
93
+ counts << "#{steps_failed} failed" if steps_failed > 0
94
+ counts << "#{steps_passing} passed" if steps_passing > 0
95
+
96
+ # 35 steps (23 skipped, 1 undefined, 3 pending, 8 passed)
97
+ case counts.count
98
+ when 4
99
+ summary << "#{steps} #{pluralize(steps, "step")} (#{counts[0]}, #{counts[1]}, #{counts[2]},\n#{counts[3]})"
100
+ when 5
101
+ summary << "#{steps} #{pluralize(steps, "step")} (#{counts[0]}, #{counts[1]}, #{counts[2]},\n#{counts[3]}, #{counts[4]})"
102
+ else
103
+ summary << "#{steps} #{pluralize(steps, "step")} (#{ counts.join(', ') })"
104
+ end
105
+
106
+ summary
107
+ end
108
+
109
+ def print_summary(features)
110
+ body = []
111
+ body << summary_line(features)
112
+
113
+ # 0m0.024s
114
+ body << "#{ format_duration(features.duration) }"
115
+
116
+ name = File.basename(File.expand_path('.'))
117
+
118
+ title = unless step_mother.scenarios(:failed).empty?
119
+ "\u26D4 #{ name }: #{ step_mother.scenarios(:failed).count } failed #{ pluralize(step_mother.scenarios(:failed).count, 'scenario') }"
120
+ else
121
+ "\u2705 #{ name }: Success"
122
+ end
123
+
124
+ say title, body.join("\n")
125
+ end
126
+
127
+ def say(title, body)
128
+ if TerminalNotifier.available?
129
+ TerminalNotifier.notify body, :title => title, :sender => 'com.apple.Terminal'
130
+ else
131
+ puts "\e[1;39;49m#{title}\e[0m"
132
+ puts body
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,25 @@
1
+ require 'capybara'
2
+
3
+ # Alias :selenium to :firefox
4
+ Capybara.register_driver :firefox do |app|
5
+ Capybara.drivers[:selenium]
6
+ end
7
+
8
+ # If a scenario is tagged as @ui and more than one capybara driver this hook
9
+ # will pick it up and run it in each browser
10
+ Around '@ui' do |scenario, block|
11
+ tags = scenario.source_tag_names.map do |tag|
12
+ tag.sub(/^@/, '').to_sym
13
+ end
14
+
15
+ common_drivers = tags & Capybara.drivers.keys
16
+
17
+ if common_drivers.count <= 1
18
+ Capybara.current_driver = common_drivers.first unless common_drivers.empty?
19
+ block.call
20
+ else
21
+ common_drivers.each do |driver|
22
+ Capybara.using_driver(driver, &block)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'capybara'
2
+
3
+ # Takes each value in a comma separated list and registers it as a
4
+ # Capybara driver
5
+ ENV['CAPYBARA_DRIVERS'].split(/,\s*/).map(&:to_sym).each do |driver|
6
+ case driver
7
+ when :poltergeist
8
+ require 'capybara/poltergeist'
9
+
10
+ file_name = ENV['PHANTOMJS_LOG_FILE'] || 'phantomjs.log'
11
+ Capybara.register_driver :poltergeist do |app|
12
+ options = {
13
+ # By default Javascript errors will be reraised in Ruby
14
+ # :js_errors => false,
15
+ :phantomjs_options => %w[--ignore-ssl-errors=yes],
16
+ :phantomjs_logger => File.open(file_name, 'a+')
17
+ }
18
+ Capybara::Poltergeist::Driver.new(app, options)
19
+ end
20
+ else
21
+ Capybara.register_driver driver do |app|
22
+ Capybara::Selenium::Driver.new(app, :browser => driver)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ require 'cucumber/rapid7/auxiliary'
2
+
3
+ # OPTIMIZE: Include helper methods on a global scope, so that they can be used in around hooks
4
+ include Cucumber::Rapid7::Auxiliary
5
+
6
+ Around do |scenario, block|
7
+ scenario_name = find_scenario_name(scenario)
8
+ source_tags = scenario.source_tag_names
9
+ common_tags = source_tags & ENV['CUCUMBER_SKIP_TAGS'].to_s.split(/,/)
10
+ example_row = scenario.is_a?(Cucumber::Ast::OutlineTable::ExampleRow)
11
+
12
+ if common_tags.any? && scenario_name.eql?(@last_scenario_name)
13
+ # TODO: Would this always an example row? If not should scenario names be unique?
14
+ if example_row
15
+ $stdout.print example_row_from_scenario(scenario)
16
+ end
17
+ elsif common_tags.any?
18
+ file_name = ENV['CUCUMBER_RERUN_FILE'] || 'rerun.txt'
19
+
20
+ File.open(file_name, 'w+') do |rerun_file|
21
+ rerun_file << " #{find_file_colon_line(scenario)}"
22
+ end
23
+
24
+ $stdout.puts skip_tag_error(scenario_name, common_tags, example_row)
25
+
26
+ if example_row
27
+ # "\s"*6 => six space chars
28
+ $stdout.print "\s"*6, '|', example_row_from_scenario(scenario)
29
+ end
30
+ else
31
+ block.call
32
+ end
33
+
34
+ @last_scenario_name = scenario_name
35
+ end
@@ -0,0 +1,8 @@
1
+ After '@ui', '@wip' do |scenario|
2
+ scenario_name = find_scenario_name(scenario)
3
+
4
+ unless ENV['CI']
5
+ $stdout.puts "\a\nPaused on '#{scenario_name}'. Press enter/return to continue to the next test."
6
+ $stdin.gets
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Cucumber
2
+ module Rapid7
3
+ VERSION = '0.0.1.beta.1'
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'cucumber/rapid7/version'
2
+
3
+ module Cucumber
4
+ module Rapid7
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-rapid7
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.beta.1
5
+ platform: ruby
6
+ authors:
7
+ - Erran Carey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '1.3'
25
+ prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :development
41
+ description: Cucumber extensions used at Rapid7
42
+ email:
43
+ - erran_carey@rapid7.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.md
51
+ - README.md
52
+ - Rakefile
53
+ - cucumber-rapid7.gemspec
54
+ - lib/cucumber/rapid7.rb
55
+ - lib/cucumber/rapid7/auxiliary.rb
56
+ - lib/cucumber/rapid7/formatter/html_postponed.rb
57
+ - lib/cucumber/rapid7/formatter/jira_metrics.rb
58
+ - lib/cucumber/rapid7/formatter/notification_center.rb
59
+ - lib/cucumber/rapid7/hooks/capybara.rb
60
+ - lib/cucumber/rapid7/hooks/capybara_register_drivers.rb
61
+ - lib/cucumber/rapid7/hooks/postponed.rb
62
+ - lib/cucumber/rapid7/hooks/ui.rb
63
+ - lib/cucumber/rapid7/version.rb
64
+ homepage: https://github.com/ecarey-r7/cucumber-rapid7
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>'
80
+ - !ruby/object:Gem::Version
81
+ version: 1.3.1
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.1.9
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Cucumber extensions for Rapid7
88
+ test_files: []