Skip to content
This repository was archived by the owner on Oct 16, 2019. It is now read-only.

Commit c02b43f

Browse files
committed
Merge branch 'bug-35'
Conflicts: Gemfile.lock allure-rspec.gemspec lib/allure-rspec/version.rb
2 parents eeceaff + f2791dd commit c02b43f

7 files changed

+113
-51
lines changed

Gemfile.lock

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
PATH
22
remote: .
33
specs:
4-
allure-rspec (0.6.8)
5-
allure-ruby-adaptor-api (= 0.6.5)
6-
rspec (~> 3.0)
4+
allure-rspec (0.6.9)
5+
allure-ruby-adaptor-api (= 0.6.6)
6+
rspec (~> 3.2)
77

88
GEM
99
remote: https://rubygems.org/
1010
specs:
11-
allure-ruby-adaptor-api (0.6.5)
11+
allure-ruby-adaptor-api (0.6.6)
1212
mimemagic
1313
nokogiri (~> 1.6.0)
1414
uuid
@@ -17,21 +17,22 @@ GEM
1717
systemu (~> 2.6.2)
1818
mimemagic (0.2.1)
1919
mini_portile (0.6.2)
20-
nokogiri (1.6.5)
20+
nokogiri (1.6.6.2)
2121
mini_portile (~> 0.6.0)
22-
rake (10.3.2)
23-
rspec (3.1.0)
24-
rspec-core (~> 3.1.0)
25-
rspec-expectations (~> 3.1.0)
26-
rspec-mocks (~> 3.1.0)
27-
rspec-core (3.1.7)
28-
rspec-support (~> 3.1.0)
29-
rspec-expectations (3.1.2)
22+
rake (10.4.2)
23+
rspec (3.2.0)
24+
rspec-core (~> 3.2.0)
25+
rspec-expectations (~> 3.2.0)
26+
rspec-mocks (~> 3.2.0)
27+
rspec-core (3.2.0)
28+
rspec-support (~> 3.2.0)
29+
rspec-expectations (3.2.0)
3030
diff-lcs (>= 1.2.0, < 2.0)
31-
rspec-support (~> 3.1.0)
32-
rspec-mocks (3.1.3)
33-
rspec-support (~> 3.1.0)
34-
rspec-support (3.1.2)
31+
rspec-support (~> 3.2.0)
32+
rspec-mocks (3.2.0)
33+
diff-lcs (>= 1.2.0, < 2.0)
34+
rspec-support (~> 3.2.0)
35+
rspec-support (3.2.1)
3536
systemu (2.6.4)
3637
uuid (2.3.7)
3738
macaddr (~> 1.0)

allure-rspec.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
1818
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
1919
s.require_paths = ['lib']
2020

21-
s.add_dependency 'rspec', '~> 3.0'
22-
s.add_dependency 'allure-ruby-adaptor-api', '0.6.5'
21+
s.add_dependency 'rspec', '~> 3.2'
22+
s.add_dependency 'allure-ruby-adaptor-api', '0.6.6'
2323

2424
s.add_development_dependency 'bundler'
2525
s.add_development_dependency 'rake'

lib/allure-rspec/formatter.rb

+31-3
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,44 @@ def stop_test(example, opts = {})
7272
end
7373

7474
def metadata(example_or_group)
75-
(example_or_group.respond_to? :group) ?
75+
group?(example_or_group) ?
7676
example_or_group.group.metadata :
7777
example_or_group.example.metadata
7878
end
7979

80+
def group?(example_or_group)
81+
(example_or_group.respond_to? :group)
82+
end
83+
8084
def labels(example_or_group)
81-
ALLOWED_LABELS.
82-
map { |label| [label, metadata(example_or_group)[label]] }.
85+
labels = ALLOWED_LABELS.map { |label| [label, metadata(example_or_group)[label]] }.
8386
find_all { |value| !value[1].nil? }.
8487
inject({}) { |res, value| res.merge(value[0] => value[1]) }
88+
detect_feature_story(labels, example_or_group)
89+
labels
90+
end
91+
92+
def method_or_key(metadata, key)
93+
metadata.respond_to?(key) ? metadata.send(key) : metadata[key]
94+
end
95+
96+
def detect_feature_story(labels, example_or_group)
97+
metadata = metadata(example_or_group)
98+
is_group = group?(example_or_group)
99+
parent = (method_or_key(metadata, :parent_example_group))
100+
if labels[:feature] === true
101+
description = (!is_group && parent) ? method_or_key(parent, :description) : method_or_key(metadata, :description)
102+
labels[:feature] = description
103+
if labels[:story] === true
104+
if parent
105+
grandparent = parent && method_or_key(parent, :parent_example_group)
106+
labels[:feature] = (!is_group && grandparent) ? method_or_key(grandparent, :description) :
107+
method_or_key(parent, :description)
108+
end
109+
labels[:story] = description
110+
end
111+
end
112+
labels
85113
end
86114

87115
end

lib/allure-rspec/hooks.rb

+47-25
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,68 @@ module OverrideHooksMethods
1111
alias_method :old_hooks, :hooks
1212

1313
def hooks
14-
if @__hooks.nil?
15-
old = old_hooks
16-
@__hooks ||= OverridenHookCollections.new(old.instance_variable_get(:@owner), old.instance_variable_get(:@data))
17-
[:before, :after].each { |scope|
18-
@__hooks[scope][:step] = HookCollection.new
19-
}
20-
end
21-
@__hooks
14+
@__hooks ||= OverridenHookCollections.new(self, RSpec::Core::FilterableItemRepository::UpdateOptimized)
2215
end
2316

2417
private
2518

2619
class OverridenHookCollections < RSpec::Core::Hooks::HookCollections
27-
private
20+
def initialize(*args)
21+
super
22+
@before_step_hooks = nil
23+
@after_step_hooks = nil
24+
end
2825

29-
SCOPES = [:example, :context, :suite, :step]
3026

31-
def before_step_hooks_for(example)
32-
RSpec::Core::Hooks::HookCollection.new(RSpec::Core::FlatMap.flat_map(@owner.parent_groups.reverse) do |a|
33-
a.hooks[:before][:step]
34-
end).for(example)
27+
def run(position, scope, example_or_group)
28+
if scope == :step
29+
run_owned_hooks_for(position, scope, example_or_group)
30+
else
31+
super
32+
end
3533
end
3634

37-
def after_step_hooks_for(example)
38-
RSpec::Core::Hooks::HookCollection.new(RSpec::Core::FlatMap.flat_map(@owner.parent_groups) do |a|
39-
a.hooks[:after][:step]
40-
end).for(example)
35+
protected
36+
37+
# TODO: This code is highly related to the RSpec internals.
38+
# It should be supported with every new RSpec version
39+
def matching_hooks_for(position, scope, example_or_group)
40+
if scope == :step
41+
repo = hooks_for(position, scope) || example_or_group.example_group.hooks.hooks_for(position, scope)
42+
metadata = case example_or_group
43+
when RSpec::Core::ExampleGroup then
44+
example_or_group.class.metadata
45+
else
46+
example_or_group.metadata
47+
end
48+
repo.nil? ? EMPTY_HOOK_ARRAY : repo.items_for(metadata)
49+
else
50+
super
51+
end
4152
end
4253

43-
def find_hook(hook, scope, example_or_group, initial_procsy)
44-
case [hook, scope]
45-
when [:before, :step]
46-
before_step_hooks_for(example_or_group)
47-
when [:after, :step]
48-
after_step_hooks_for(example_or_group)
54+
def hooks_for(position, scope)
55+
if scope == :step
56+
position == :before ? @before_step_hooks : @after_step_hooks
57+
else
58+
super
59+
end
60+
end
61+
62+
def ensure_hooks_initialized_for(position, scope)
63+
if scope == :step
64+
if position == :before
65+
@before_step_hooks ||= @filterable_item_repo_class.new(:all?)
4966
else
50-
super(hook, scope, example_or_group, initial_procsy)
67+
@after_step_hooks ||= @filterable_item_repo_class.new(:all?)
68+
end
69+
else
70+
super
5171
end
5272
end
5373

74+
SCOPES = [:example, :context, :step]
75+
5476
def known_scope?(scope)
5577
SCOPES.include?(scope) || super(scope)
5678
end

lib/allure-rspec/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module AllureRSpec # :nodoc:
22
module Version # :nodoc:
3-
STRING = '0.6.8'
3+
STRING = '0.6.9'
44
end
55
end

spec/nometavalue_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'spec_helper'
2+
require 'tempfile'
3+
4+
describe "Some feature", :feature do
5+
describe "Some story", :story do
6+
it "20 should be greater than 19", :story do
7+
expect(20).to be > 19
8+
end
9+
end
10+
11+
end

spec/shared_example_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66

77
context "initialized with 3 items" do
88
it "says it has three items" do
9-
collection.size.should eq(3)
9+
expect(collection.size).to be 3
1010
end
1111
end
1212

1313
describe "#include?" do
1414
context "with an an item that is in the collection" do
1515
it "returns true" do
16-
collection.include?(7).should be_true
16+
expect(collection.include?(7)).to be true
1717
end
1818
end
1919

2020
context "with an an item that is not in the collection" do
2121
it "returns false" do
22-
collection.include?(9).should be_false
22+
expect(collection.include?(9)).to be false
2323
end
2424
end
2525
end

0 commit comments

Comments
 (0)