cukerail 0.0.2

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: 2766250f6ab930d87a486fe29cf12d953a96ac28
4
+ data.tar.gz: 2163570c2c5f60002ac0de36b55ffbabbb2fa653
5
+ SHA512:
6
+ metadata.gz: 4782fa57ad5d3d403cf07f0697a66f5e99976cee441c71ccbbc444bceb7b447467faed37e19265cc71dfc5b49ef3718b5d824fd393e006ce944c1da7f0668890
7
+ data.tar.gz: 0aeb164dac7a5013690d62a31b5430646e4894b06565ea224be7bdbae51669e55879197c013c69148ec5af00f4d0d44885e056ce21777eec82ee4be6b3f2e843
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cukerail.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 John Small
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
+ # Cukerail
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cukerail'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cukerail
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/cukerail/fork )
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 a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Default directory to look in is `/specs`
5
+ # # Run with `rake spec`
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ task.rspec_opts = ['--color', '--format', 'documentation']
8
+ end
9
+
10
+ task :default => :spec
11
+
data/cukerail.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cukerail/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cukerail"
8
+ spec.version = Cukerail::VERSION
9
+ spec.authors = ["John Small"]
10
+ spec.email = ["john.small@bbc.com"]
11
+ spec.summary = %q{Integrates Cucumber and Testrail from Gurock Software}
12
+ spec.description = %q{Allows you to sync your Testrail testcases from feature files and send test results into Testrail testruns}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.6"
22
+ spec.add_development_dependency "rake","~>10.4"
23
+ spec.add_development_dependency "rspec","~>3.2"
24
+ spec.add_development_dependency "pry","~>0.10"
25
+ spec.add_development_dependency "geminabox","~>0.12"
26
+ end
@@ -0,0 +1,3 @@
1
+ module Cukerail
2
+ VERSION = "0.0.2"
3
+ end
data/lib/cukerail.rb ADDED
@@ -0,0 +1,137 @@
1
+ require "cukerail/version"
2
+ require "testrail"
3
+ module Cukerail
4
+ class Sender
5
+ attr_reader :conn
6
+ def initialize(runtime, io, options)
7
+ @conn = TestRail::APIClient.new(ENV['TESTRAIL_BASE_URL'],ENV['TESTRAIL_USER'],ENV['TESTRAIL_PASSWORD'])
8
+ end
9
+
10
+ def after_test_case(test_case,result)
11
+ feature = test_case.feature
12
+ # ap feature.methods - Object.methods
13
+ # ap feature.tags
14
+ @id = get_id(test_case)
15
+ raise 'No id found' unless @id
16
+ send_steps(test_case,@id)
17
+ send_result(test_case,result,@id,ENV['TESTRUN']) if ENV['TESTRUN']
18
+ end
19
+
20
+ def tag_name(tag_name)
21
+ @scenario_tags << tag_name
22
+ end
23
+
24
+ def step_name(keyword, step_match, status, source_indent, background, file_colon_line)
25
+ step_name = step_match.format_args(lambda{|param| "*#{param}*"})
26
+ @test_steps << "#{keyword}#{step_name}"
27
+ end
28
+
29
+ def after_test_step(step,result)
30
+ unless result.passed?
31
+ # only the first non-passed step
32
+ @failed_step[:step] ||= step
33
+ @failed_step[:result] ||= result
34
+ end
35
+ end
36
+
37
+ def before_test_case(*args)
38
+ @test_steps =[]
39
+ @scenario_tags = []
40
+ @failed_step = {}
41
+ end
42
+
43
+ def get_id(test_case)
44
+ # ap test_case.methods - Object.methods
45
+ tagged_id = test_case.tags.select{|tag| tag.name =~/testcase/}.first
46
+ tags = test_case.tags + test_case.feature.tags
47
+ project_id = /\d+/.match(tags.select{|tag| tag.name =~/project/}.first.name)[0]
48
+ suite_id = /\d+/.match(tags.select{|tag| tag.name =~/suite/}.first.name)[0]
49
+ title = extract_title(test_case)
50
+ found_case = @conn.send_get("get_cases/#{project_id}&suite_id=#{suite_id}").select{|c| c['title'] == title}.first
51
+ if found_case
52
+ result= found_case['id']
53
+ else
54
+ sub_section_id = /\d+/.match(tags.select{|tag| tag.name =~/sub_section/}.first.name)[0]
55
+ result = create_new_case(project_id,suite_id,sub_section_id,test_case)['id']
56
+ end
57
+ return result
58
+ end
59
+
60
+ def update_source_file(scenario, external_reference)
61
+ #this could be done on one line with sed. But the format is different on Mac OS and GNU Linux version and it definitely won't work on a Windows machine
62
+ path = scenario.file
63
+ lines = IO.readlines(scenario.file)
64
+ lines[scenario.line-2].gsub!(/ @testcase_\d*/," @testcase_#{external_reference}")
65
+ lines[scenario.line-2].gsub!(/\n/," @testcase_#{external_reference}") unless lines[scenario.line-2] =~ /testcase/
66
+ temp_file = Tempfile.new('foo')
67
+ begin
68
+ File.open(path, 'r') do |file|
69
+ lines.each do |line|
70
+ temp_file.puts line
71
+ end
72
+ end
73
+ temp_file.close
74
+ FileUtils.mv(temp_file.path, path)
75
+ ensure
76
+ temp_file.close
77
+ temp_file.unlink
78
+ end
79
+ end
80
+
81
+ def send_steps(test_case,id)
82
+ steps_as_string = test_case.test_steps.map{|step| step.source.last}.select{|step| step.is_a?(Cucumber::Core::Ast::Step)}.map do | step |
83
+ g = step.gherkin_statement
84
+ str = g.keyword+g.name
85
+ g.rows.each do | row |
86
+ str += "\n| #{row.cells.join(' | ')} |"
87
+ end if g.rows
88
+ str
89
+ end.join("\n")
90
+ is_manual = test_case.tags.any?{|tag| tag.name =~/manual/}
91
+ data = {'title'=>extract_title(test_case),'type_id'=>(is_manual ? 7 : 1 ),'custom_steps'=>steps_as_string}
92
+ @conn.send_post("update_case/#{id}",data)
93
+ end
94
+
95
+ def create_new_case(project_id,suite_id,sub_section_id,test_case)
96
+ is_manual = test_case.tags.any?{|tag| tag.name =~/manual/}
97
+ steps_as_string = test_case.test_steps.map{|step| step.source.last}.select{|step| step.is_a?(Cucumber::Core::Ast::Step)}.map{|step| "#{step.keyword}#{step.name}"}.join("\n")
98
+ data = {'title'=>extract_title(test_case),'type_id'=>(is_manual ? 7 : 1 ),'custom_steps'=>steps_as_string}
99
+ @conn.send_post("add_case/#{sub_section_id || suite_id}", data)
100
+ end
101
+
102
+ def send_result(test_case,result,id,testrun)
103
+ testrail_status = case
104
+ when result.passed?
105
+ {id:1,comment: 'passed'}
106
+ when result.failed?
107
+ {id:5,comment: 'failed'}
108
+ when result.undefined?
109
+ {id:7,comment: 'undefined step'}
110
+ when result.pending?
111
+ {id:6,comment: 'pending step'}
112
+ end
113
+ unless result.passed?
114
+ failure_message = <<-FAILURE
115
+ Error message: #{testrail_status[:comment]} #{result.exception.message}
116
+ Step: #{@failed_step[:step].source.last.keyword}#{@failed_step[:step].source.last.name}
117
+ Location: #{@failed_step[:step].source.last.file_colon_line}
118
+ FAILURE
119
+ else
120
+ failure_message = nil
121
+ end
122
+ defects = test_case.tags.select{|tag| tag.name =~/jira_/}.map{|ticket| /STORE-\d+/.match(ticket.name)[0]}.join(" ")
123
+ report_on_result = {status_id:testrail_status[:id],comment:failure_message,defects:defects}
124
+ @conn.send_post("add_result_for_case/#{testrun}/#{id}",report_on_result)
125
+ end
126
+ def extract_title(test_case)
127
+ if test_case.source.last.is_a?(Cucumber::Core::Ast::ExamplesTable::Row)
128
+ title = test_case.source.select{|s| s.is_a?(Cucumber::Core::Ast::ScenarioOutline)}.first.title
129
+ title += " "+test_case.source.last.send(:data).map{|key,value| "#{key}=#{value}"}.join(', ')
130
+ else
131
+ title = test_case.source.last.title
132
+ end
133
+ end
134
+
135
+ end
136
+
137
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cukerail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - John Small
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: geminabox
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.12'
83
+ description: Allows you to sync your Testrail testcases from feature files and send
84
+ test results into Testrail testruns
85
+ email:
86
+ - john.small@bbc.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - cukerail.gemspec
97
+ - lib/cukerail.rb
98
+ - lib/cukerail/version.rb
99
+ homepage: ''
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.2.2
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Integrates Cucumber and Testrail from Gurock Software
123
+ test_files: []