allure-rspec 0.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: d5172f300f2a968898c79b3db59c0fc632c2d74c
4
+ data.tar.gz: 6a63f38b078f320a38b8b4c133e032c64f7c94dd
5
+ SHA512:
6
+ metadata.gz: 030995aae4cb005e6a498222a3050d484ab1aa825f63a0e3ff97768fc4f069161831a503d5e70be70a44c1d898f77b7495518700342816e77402a022ad1f100f
7
+ data.tar.gz: a49109b6de8af85d44ebcb3b49bfc101fd53bb584c59498cdebb756ac5fc29875f075e37f0f7d2f812241bbe9dbd547afa91f152dc429782eb8b7206f306b8f9
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ *.class
2
+
3
+ # Package Files #
4
+ *.jar
5
+ *.war
6
+ *.ear
7
+ *.gem
8
+
9
+ target
10
+ allure
11
+ .idea
12
+ *.iml
13
+ *.ipr
14
+ *.iws
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'rspec-steps', '~> 0.1.1'
5
+ gem 'nokogiri', '~> 1.6.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ Allure RSpec Adaptor (0.1)
5
+ nokogiri
6
+ rspec-steps (~> 0.1.1)
7
+ uuid
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ diff-lcs (1.2.5)
13
+ macaddr (1.6.1)
14
+ systemu (~> 2.5.0)
15
+ mini_portile (0.5.2)
16
+ nokogiri (1.6.0)
17
+ mini_portile (~> 0.5.0)
18
+ rake (10.1.0)
19
+ rspec (2.13.0)
20
+ rspec-core (~> 2.13.0)
21
+ rspec-expectations (~> 2.13.0)
22
+ rspec-mocks (~> 2.13.0)
23
+ rspec-core (2.13.1)
24
+ rspec-expectations (2.13.0)
25
+ diff-lcs (>= 1.1.3, < 2.0)
26
+ rspec-mocks (2.13.1)
27
+ rspec-steps (0.1.1)
28
+ rspec (>= 2.6, < 2.14.0)
29
+ systemu (2.5.2)
30
+ uuid (2.3.7)
31
+ macaddr (~> 1.0)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ Allure RSpec Adaptor!
38
+ bundler
39
+ nokogiri (~> 1.6.0)
40
+ rake
41
+ rspec-steps (~> 0.1.1)
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Allure RSpec Adaptor
2
+
3
+ Adaptor to use the Allure framework along with the RSpec
4
+
5
+ ## Setup
6
+
7
+ Add the dependency to your Gemfile
8
+
9
+ ```ruby
10
+ gem 'allure-rspec'
11
+ ```
12
+
13
+ And then include it in your spec_helper.rb:
14
+
15
+ ```ruby
16
+ RSpec.configure do |c|
17
+ c.include AllureRSpec::Adaptor
18
+ end
19
+ ```
20
+
21
+ ## Advanced options
22
+
23
+ You can specify the directory where the Allure test results will appear. By default it would be 'allure/data' within
24
+ your current directory.
25
+
26
+ ```ruby
27
+ AllureRSpec.configure do |c|
28
+ c.output_dir = "/whatever/you/like"
29
+ end
30
+ ```
31
+
32
+ ## Usage examples
33
+
34
+ ```ruby
35
+ describe AllureRSpec do
36
+
37
+ it "should build" do
38
+ step "step1" do
39
+ attach_file "screenshot1", take_screenshot_as_file
40
+ end
41
+
42
+ step "step2" do
43
+ 5.should be < 1
44
+ end
45
+
46
+ step "step3" do
47
+ 0.should == 0
48
+ end
49
+
50
+ attach_file "screenshot2", take_screenshot_as_file
51
+ end
52
+ end
53
+ ```
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
+ require "allure-rspec/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'allure-rspec'
7
+ s.version = AllureRSpec::Version::STRING
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Ilya Sadykov']
10
+ s.email = ['smecsia@yandex-team.ru']
11
+ s.description = %q{Adaptor to use Allure framework along with the RSpec 2}
12
+ s.summary = "allure-rspec-#{AllureRSpec::Version::STRING}"
13
+ s.homepage = 'http://allure.qatools.ru'
14
+ s.license = 'Apache2'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ['lib']
20
+
21
+ s.add_dependency 'rspec-steps', '~> 0.1.1'
22
+ s.add_dependency 'nokogiri'
23
+ s.add_dependency 'uuid'
24
+
25
+ s.add_development_dependency 'bundler'
26
+ s.add_development_dependency 'rake'
27
+ end
@@ -0,0 +1,28 @@
1
+ require 'allure-rspec/version'
2
+ require 'allure-rspec/formatter'
3
+ require 'allure-rspec/adaptor'
4
+ require 'allure-rspec/dsl'
5
+ require 'allure-rspec/builder'
6
+
7
+ module AllureRSpec
8
+ include AllureRSpec::DSL
9
+
10
+ module Config
11
+ class << self
12
+ attr_accessor :output_dir
13
+
14
+ DEFAULT_OUTPUT_DIR = 'allure/data'
15
+
16
+ def output_dir
17
+ @output_dir || DEFAULT_OUTPUT_DIR
18
+ end
19
+ end
20
+ end
21
+
22
+ class << self
23
+ def configure(&block)
24
+ yield Config
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,9 @@
1
+ module AllureRSpec
2
+ module Adaptor
3
+ def self.included(base)
4
+ base.send :include, AllureRSpec::DSL
5
+ RSpec.configuration.add_formatter(AllureRSpec::Formatter)
6
+ end
7
+ end
8
+ end
9
+
@@ -0,0 +1,150 @@
1
+ require 'rexml/text'
2
+
3
+ module AllureRSpec
4
+
5
+ class Builder
6
+ class << self
7
+ attr_accessor :suites
8
+ MUTEX = Mutex.new
9
+
10
+ def init_suites
11
+ MUTEX.synchronize {
12
+ self.suites ||= {}
13
+ }
14
+ end
15
+
16
+ def start_suite(title)
17
+ init_suites
18
+ MUTEX.synchronize do
19
+ puts "Starting suite #{title}"
20
+ self.suites[title] = {
21
+ :title => title,
22
+ :start => timestamp,
23
+ :tests => {},
24
+ }
25
+ end
26
+ end
27
+
28
+ def start_test(suite, test, severity = :normal)
29
+ MUTEX.synchronize do
30
+ puts "Starting test #{suite}.#{test}"
31
+ self.suites[suite][:tests][test] = {
32
+ :title => test,
33
+ :start => timestamp,
34
+ :severity => severity,
35
+ :failure => nil,
36
+ :steps => {},
37
+ :attachments => []
38
+ }
39
+ end
40
+ end
41
+
42
+ def stop_test(suite, test, result = {})
43
+ self.suites[suite][:tests][test][:steps].each do |step_title, step|
44
+ if step[:stop].nil? || step[:stop] == 0
45
+ stop_step(suite, test, step_title, result[:status])
46
+ end
47
+ end
48
+ MUTEX.synchronize do
49
+ puts "Stopping test #{suite}.#{test}"
50
+ self.suites[suite][:tests][test][:stop] = timestamp(result[:started_at])
51
+ self.suites[suite][:tests][test][:start] = timestamp(result[:finished_at])
52
+ self.suites[suite][:tests][test][:status] = result[:status]
53
+ if (result[:status].to_sym != :passed)
54
+ self.suites[suite][:tests][test][:failure] = {
55
+ :stacktrace => escape((result[:caller] || []).map { |s| s.to_s }.join("\r\n")),
56
+ :message => escape(result[:exception].to_s),
57
+ }
58
+ end
59
+
60
+ end
61
+ end
62
+
63
+ def escape(text)
64
+ REXML::Text.new(text, false, nil, false)
65
+ end
66
+
67
+ def start_step(suite, test, step, severity = :normal)
68
+ MUTEX.synchronize do
69
+ puts "Starting step #{suite}.#{test}.#{step}"
70
+ self.suites[suite][:tests][test][:steps][step] = {
71
+ :title => step,
72
+ :start => timestamp,
73
+ :severity => severity || :normal,
74
+ :attachments => []
75
+ }
76
+ end
77
+ end
78
+
79
+ def add_attachment(suite, test, attachment, step = nil)
80
+ attach = {
81
+ :title => attachment[:title],
82
+ :source => attachment[:source],
83
+ :type => attachment[:type],
84
+ }
85
+ if step.nil?
86
+ self.suites[suite][:tests][test][:attachments] << attach
87
+ else
88
+ self.suites[suite][:tests][test][:steps][step][:attachments] << attach
89
+ end
90
+ end
91
+
92
+ def stop_step(suite, test, step, status = :passed)
93
+ MUTEX.synchronize do
94
+ puts "Stopping step #{suite}.#{test}.#{step}"
95
+ self.suites[suite][:tests][test][:steps][step][:stop] = timestamp
96
+ self.suites[suite][:tests][test][:steps][step][:status] = status
97
+ end
98
+ end
99
+
100
+ def stop_suite(title)
101
+ init_suites
102
+ MUTEX.synchronize do
103
+ puts "Stopping suite #{title}"
104
+ self.suites[title][:stop] = timestamp
105
+ end
106
+ end
107
+
108
+ def timestamp(time = nil)
109
+ ((time || Time.now).to_f * 1000).to_i
110
+ end
111
+
112
+ def each_suite_build(&block)
113
+ suites_xml = []
114
+ self.suites.each do |suite_title, suite|
115
+ builder = Nokogiri::XML::Builder.new do
116
+ send "test-suite", :start => suite[:start] || 0, :stop => suite[:stop] || 0 do
117
+ title suite_title
118
+ suite[:tests].each do |test_title, test|
119
+ send "test-cases", :start => test[:start] || 0, :stop => test[:stop] || 0, :status => test[:status], :severity => test[:severity] do
120
+ title test_title
121
+ unless test[:failure].nil?
122
+ failure do
123
+ message test[:failure][:message]
124
+ send "stack-trace", test[:failure][:stacktrace]
125
+ end
126
+ end
127
+ test[:steps].each do |step_title, step_obj|
128
+ steps(:start => step_obj[:start] || 0, :stop => step_obj[:stop] || 0, :status => step_obj[:status]) do
129
+ title step_title
130
+ step_obj[:attachments].each do |attach|
131
+ attachment :source => attach[:source], :title => attach[:title], :type => attach[:type]
132
+ end
133
+ end
134
+ end
135
+ test[:attachments].each do |attach|
136
+ attachment :source => attach[:source], :title => attach[:title], :type => attach[:type]
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
142
+ xml = builder.to_xml
143
+ yield suite, xml
144
+ suites_xml << xml
145
+ end
146
+ suites_xml
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,45 @@
1
+ module AllureRSpec
2
+ module DSL
3
+
4
+ ALLOWED_ATTACH_EXTS = %w[txt html xml png jpg json]
5
+
6
+ def __mutex
7
+ @@__mutex ||= Mutex.new
8
+ end
9
+
10
+ def __current_step
11
+ if defined? @@__current_step
12
+ @@__current_step
13
+ else
14
+ nil
15
+ end
16
+ end
17
+
18
+ def __with_step(step, &block)
19
+ __mutex.synchronize do
20
+ @@__current_step = step
21
+ yield
22
+ @@__current_step = nil
23
+ end
24
+ end
25
+
26
+ def step(step, &block)
27
+ suite = self.example.metadata[:example_group][:description_args].first
28
+ test = self.example.metadata[:description]
29
+ AllureRSpec::Builder.start_step(suite, test, step)
30
+ __with_step step, &block
31
+ AllureRSpec::Builder.stop_step(suite, test, step)
32
+ end
33
+
34
+ def attach_file(title, file)
35
+ step = __current_step
36
+ suite = self.example.metadata[:example_group][:description_args].first
37
+ test = self.example.metadata[:description]
38
+ type = :other
39
+ file_extname = File.extname(file.path.downcase)
40
+ type = file_extname if ALLOWED_ATTACH_EXTS.include?(file_extname)
41
+ AllureRSpec::Builder.add_attachment(suite, test, {:type => type, :title => title, :source => file.path}, step)
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,60 @@
1
+ require 'pathname'
2
+ require 'uuid'
3
+
4
+ module AllureRSpec
5
+
6
+ class Formatter < RSpec::Core::Formatters::BaseFormatter
7
+
8
+ def example_failed(example)
9
+ AllureRSpec::Builder.stop_test(
10
+ example.metadata[:example_group][:description_args].first,
11
+ example.metadata[:description],
12
+ example.metadata[:execution_result].merge(:caller => example.metadata[:caller])
13
+ )
14
+ super
15
+ end
16
+
17
+ def example_group_finished(group)
18
+ AllureRSpec::Builder.stop_suite(group.metadata[:example_group][:description_args].first)
19
+ super
20
+ end
21
+
22
+ def example_group_started(group)
23
+ AllureRSpec::Builder.start_suite(group.metadata[:example_group][:description_args].first)
24
+ super
25
+ end
26
+
27
+ def example_passed(example)
28
+ AllureRSpec::Builder.stop_test(
29
+ example.metadata[:example_group][:description_args].first,
30
+ example.metadata[:description],
31
+ example.metadata[:execution_result].merge(:caller => example.metadata[:caller])
32
+ )
33
+ super
34
+ end
35
+
36
+ def example_pending(example)
37
+ super
38
+ end
39
+
40
+ def example_started(example)
41
+ suite = example.metadata[:example_group][:description_args].first
42
+ test = example.metadata[:description]
43
+ AllureRSpec::Builder.start_test(suite, test)
44
+ super
45
+ end
46
+
47
+ def stop
48
+ AllureRSpec::Builder.each_suite_build do |suite, xml|
49
+ dir = Pathname.new(AllureRSpec::Config.output_dir)
50
+ FileUtils.rm_rf(dir)
51
+ FileUtils.mkdir_p(dir)
52
+ File.open(dir.join("#{UUID.new.generate}.xml"), 'w+') do |file|
53
+ file.write(xml)
54
+ end
55
+ end
56
+ super
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ module AllureRSpec # :nodoc:
2
+ module Version # :nodoc:
3
+ STRING = '0.1'
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+
4
+ describe AllureRSpec do
5
+ it "should build" do
6
+ attach_file "test-file1", Tempfile.new("test")
7
+ step "step1" do
8
+ attach_file "test-file2", Tempfile.new("test")
9
+ end
10
+
11
+ step "step2" do
12
+
13
+ 5.should be < 1
14
+ end
15
+
16
+ step "step3" do
17
+
18
+ 0.should == 0
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ require 'rspec'
2
+ require 'allure-rspec'
3
+ require 'nokogiri'
4
+
5
+ RSpec.configure do |c|
6
+ c.include AllureRSpec::Adaptor
7
+ end
8
+
9
+ AllureRSpec.configure do |c|
10
+ c.output_dir = "allure"
11
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: allure-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Ilya Sadykov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec-steps
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: uuid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Adaptor to use Allure framework along with the RSpec 2
84
+ email:
85
+ - smecsia@yandex-team.ru
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - README.md
94
+ - allure-rspec.gemspec
95
+ - lib/allure-rspec.rb
96
+ - lib/allure-rspec/adaptor.rb
97
+ - lib/allure-rspec/builder.rb
98
+ - lib/allure-rspec/dsl.rb
99
+ - lib/allure-rspec/formatter.rb
100
+ - lib/allure-rspec/version.rb
101
+ - spec/extend_steps_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: http://allure.qatools.ru
104
+ licenses:
105
+ - Apache2
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: allure-rspec-0.1
127
+ test_files: []