rspec 1.1.8 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +30 -3
- data/License.txt +22 -0
- data/Manifest.txt +3 -3
- data/README.txt +1 -25
- data/Rakefile +4 -2
- data/TODO.txt +5 -4
- data/bin/autospec +1 -1
- data/examples/pure/shared_example_group_example.rb +2 -2
- data/lib/autotest/rspec.rb +1 -1
- data/lib/spec.rb +5 -1
- data/lib/spec/example.rb +1 -1
- data/lib/spec/example/before_and_after_hooks.rb +93 -0
- data/lib/spec/example/configuration.rb +10 -1
- data/lib/spec/example/example_group.rb +2 -1
- data/lib/spec/example/example_group_factory.rb +18 -1
- data/lib/spec/example/example_group_methods.rb +45 -123
- data/lib/spec/example/example_methods.rb +9 -6
- data/lib/spec/example/shared_example_group.rb +6 -12
- data/lib/spec/extensions/main.rb +1 -1
- data/lib/spec/interop/test/unit/testcase.rb +1 -1
- data/lib/spec/mocks/error_generator.rb +1 -1
- data/lib/spec/mocks/message_expectation.rb +19 -4
- data/lib/spec/mocks/methods.rb +2 -2
- data/lib/spec/mocks/proxy.rb +4 -5
- data/lib/spec/runner.rb +3 -4
- data/lib/spec/runner/formatter/nested_text_formatter.rb +3 -3
- data/lib/spec/runner/option_parser.rb +23 -22
- data/lib/spec/version.rb +1 -1
- data/rspec.gemspec +19 -8
- data/spec/autotest/rspec_spec.rb +5 -1
- data/spec/spec/example/configuration_spec.rb +229 -215
- data/spec/spec/example/example_group_class_definition_spec.rb +9 -9
- data/spec/spec/example/example_group_factory_spec.rb +48 -27
- data/spec/spec/example/example_group_methods_spec.rb +436 -426
- data/spec/spec/example/example_group_spec.rb +459 -500
- data/spec/spec/example/example_methods_spec.rb +92 -86
- data/spec/spec/example/shared_example_group_spec.rb +219 -203
- data/spec/spec/extensions/main_spec.rb +23 -23
- data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +13 -0
- data/spec/spec/interop/test/unit/spec_spec.rb +15 -8
- data/spec/spec/mocks/mock_spec.rb +12 -2
- data/spec/spec/mocks/nil_expectation_warning_spec.rb +0 -1
- data/spec/spec/mocks/partial_mock_spec.rb +10 -5
- data/spec/spec/package/bin_spec_spec.rb +8 -0
- data/spec/spec/runner/command_line_spec.rb +101 -100
- data/spec/spec/runner/drb_command_line_spec.rb +0 -2
- data/spec/spec/runner/formatter/html_formatter_spec.rb +1 -4
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +230 -245
- data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -3
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +110 -109
- data/spec/spec/runner/option_parser_spec.rb +18 -6
- data/spec/spec_helper.rb +26 -5
- data/stories/mock_framework_integration/use_flexmock.story +1 -1
- metadata +38 -7
- data/lib/spec/example/module_inclusion_warnings.rb +0 -38
- data/spec/spec/example/example_group/described_module_spec.rb +0 -20
- data/spec/spec/example/example_group/warning_messages_spec.rb +0 -76
@@ -22,116 +22,113 @@ module Spec
|
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "lifecycle" do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@count
|
25
|
+
with_sandboxed_options do
|
26
|
+
before do
|
27
|
+
@options.formatters << mock("formatter", :null_object => true)
|
28
|
+
@options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
|
29
|
+
@reporter = FakeReporter.new(@options)
|
30
|
+
@options.reporter = @reporter
|
31
|
+
|
32
|
+
ExampleGroup.before_all_parts.should == []
|
33
|
+
ExampleGroup.before_each_parts.should == []
|
34
|
+
ExampleGroup.after_each_parts.should == []
|
35
|
+
ExampleGroup.after_all_parts.should == []
|
36
|
+
def ExampleGroup.count
|
37
|
+
@count ||= 0
|
38
|
+
@count = @count + 1
|
39
|
+
@count
|
40
|
+
end
|
42
41
|
end
|
43
|
-
end
|
44
|
-
|
45
|
-
after do
|
46
|
-
Spec::Runner.use @original_rspec_options
|
47
|
-
ExampleMethods.instance_variable_set("@before_all_parts", [])
|
48
|
-
ExampleMethods.instance_variable_set("@before_each_parts", [])
|
49
|
-
ExampleMethods.instance_variable_set("@after_each_parts", [])
|
50
|
-
ExampleMethods.instance_variable_set("@after_all_parts", [])
|
51
|
-
end
|
52
42
|
|
53
|
-
|
54
|
-
|
55
|
-
|
43
|
+
after do
|
44
|
+
ExampleGroup.instance_variable_set("@before_all_parts", [])
|
45
|
+
ExampleGroup.instance_variable_set("@before_each_parts", [])
|
46
|
+
ExampleGroup.instance_variable_set("@after_each_parts", [])
|
47
|
+
ExampleGroup.instance_variable_set("@after_all_parts", [])
|
56
48
|
end
|
57
49
|
|
58
|
-
|
59
|
-
|
60
|
-
|
50
|
+
it "should pass before and after callbacks to all ExampleGroup subclasses" do
|
51
|
+
ExampleGroup.before(:suite) do
|
52
|
+
ExampleGroup.count.should == 1
|
53
|
+
end
|
61
54
|
|
62
|
-
|
63
|
-
|
64
|
-
|
55
|
+
ExampleGroup.before(:all) do
|
56
|
+
ExampleGroup.count.should == 2
|
57
|
+
end
|
65
58
|
|
66
|
-
|
67
|
-
|
68
|
-
|
59
|
+
ExampleGroup.before(:each) do
|
60
|
+
ExampleGroup.count.should == 3
|
61
|
+
end
|
69
62
|
|
70
|
-
|
71
|
-
|
72
|
-
|
63
|
+
ExampleGroup.after(:each) do
|
64
|
+
ExampleGroup.count.should == 4
|
65
|
+
end
|
73
66
|
|
74
|
-
|
75
|
-
|
76
|
-
|
67
|
+
ExampleGroup.after(:all) do
|
68
|
+
ExampleGroup.count.should == 5
|
69
|
+
end
|
77
70
|
|
78
|
-
|
79
|
-
|
71
|
+
ExampleGroup.after(:suite) do
|
72
|
+
ExampleGroup.count.should == 6
|
80
73
|
end
|
81
|
-
end
|
82
|
-
@options.run_examples
|
83
|
-
ExampleMethods.count.should == 7
|
84
|
-
end
|
85
74
|
|
86
|
-
|
87
|
-
|
88
|
-
@example_group = Class.new(ExampleGroup)
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "with a given description" do
|
92
|
-
it "should provide the given description" do
|
93
|
-
@example = @example_group.it("given description") { 2.should == 2 }
|
94
|
-
@example.eval_block
|
95
|
-
@example.description.should == "given description"
|
75
|
+
Class.new(ExampleGroup) do
|
76
|
+
it "should use ExampleMethods callbacks" do end
|
96
77
|
end
|
78
|
+
@options.run_examples
|
79
|
+
ExampleGroup.count.should == 7
|
97
80
|
end
|
98
81
|
|
99
|
-
describe "
|
100
|
-
|
101
|
-
@
|
102
|
-
@example.eval_block
|
103
|
-
@example.description.should == "should == 2"
|
82
|
+
describe "eval_block" do
|
83
|
+
before(:each) do
|
84
|
+
@example_group = Class.new(ExampleGroup)
|
104
85
|
end
|
105
|
-
end
|
106
86
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
@example = @example_group.it
|
87
|
+
describe "with a given description" do
|
88
|
+
it "should provide the given description" do
|
89
|
+
@example = @example_group.it("given description") { 2.should == 2 }
|
111
90
|
@example.eval_block
|
112
|
-
|
91
|
+
@example.description.should == "given description"
|
92
|
+
end
|
113
93
|
end
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
94
|
+
|
95
|
+
describe "with no given description" do
|
96
|
+
it "should provide the generated description" do
|
97
|
+
@example = @example_group.it { 2.should == 2 }
|
98
|
+
@example.eval_block
|
99
|
+
@example.description.should == "should == 2"
|
120
100
|
end
|
121
|
-
|
122
|
-
nil
|
123
101
|
end
|
102
|
+
|
103
|
+
describe "with no implementation" do
|
104
|
+
it "should raise an NotYetImplementedError" do
|
105
|
+
lambda {
|
106
|
+
@example = @example_group.it
|
107
|
+
@example.eval_block
|
108
|
+
}.should raise_error(Spec::Example::NotYetImplementedError, "Not Yet Implemented")
|
109
|
+
end
|
124
110
|
|
125
|
-
|
126
|
-
|
127
|
-
|
111
|
+
def extract_error(&blk)
|
112
|
+
begin
|
113
|
+
blk.call
|
114
|
+
rescue Exception => e
|
115
|
+
return e
|
116
|
+
end
|
128
117
|
|
129
|
-
|
130
|
-
@example = @example_group.it
|
131
|
-
@example.eval_block
|
118
|
+
nil
|
132
119
|
end
|
120
|
+
|
121
|
+
it "should use the proper file and line number for the NotYetImplementedError" do
|
122
|
+
file = __FILE__
|
123
|
+
line_number = __LINE__ + 3
|
133
124
|
|
134
|
-
|
125
|
+
error = extract_error do
|
126
|
+
@example = @example_group.it
|
127
|
+
@example.eval_block
|
128
|
+
end
|
129
|
+
|
130
|
+
error.pending_caller.should == "#{file}:#{line_number}"
|
131
|
+
end
|
135
132
|
end
|
136
133
|
end
|
137
134
|
end
|
@@ -159,5 +156,14 @@ module Spec
|
|
159
156
|
end
|
160
157
|
end
|
161
158
|
end
|
159
|
+
|
160
|
+
describe "#options" do
|
161
|
+
it "should expose the options hash" do
|
162
|
+
example_group = Class.new(ExampleGroup)
|
163
|
+
example = example_group.example "name", :this => 'that' do; end
|
164
|
+
example.options[:this].should == 'that'
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
162
168
|
end
|
163
169
|
end
|
@@ -3,262 +3,278 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|
3
3
|
module Spec
|
4
4
|
module Example
|
5
5
|
describe ExampleGroup, "with :shared => true" do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
with_sandboxed_options do
|
7
|
+
attr_reader :formatter, :example_group
|
8
|
+
before(:each) do
|
9
|
+
@formatter = Spec::Mocks::Mock.new("formatter", :null_object => true)
|
10
|
+
options.formatters << formatter
|
11
|
+
@example_group = Class.new(ExampleGroup).describe("example_group")
|
12
|
+
class << example_group
|
13
|
+
public :include
|
14
|
+
end
|
14
15
|
end
|
15
|
-
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def make_shared_example_group(name, opts=nil, &block)
|
24
|
-
example_group = SharedExampleGroup.new(name, :shared => true, &block)
|
25
|
-
SharedExampleGroup.add_shared_example_group(example_group)
|
26
|
-
example_group
|
27
|
-
end
|
17
|
+
after(:each) do
|
18
|
+
@formatter.rspec_verify
|
19
|
+
@example_group = nil
|
20
|
+
Spec::Example::SharedExampleGroup.shared_example_groups.clear
|
21
|
+
end
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
def make_shared_example_group(name, opts=nil, &block)
|
24
|
+
example_group = SharedExampleGroup.new(name, :shared => true, &block)
|
25
|
+
SharedExampleGroup.add_shared_example_group(example_group)
|
26
|
+
example_group
|
27
|
+
end
|
32
28
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
29
|
+
def non_shared_example_group()
|
30
|
+
@non_shared_example_group ||= Class.new(ExampleGroup).describe("example_group")
|
31
|
+
end
|
37
32
|
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
it "should accept an optional options hash" do
|
34
|
+
lambda { Class.new(ExampleGroup).describe("context") }.should_not raise_error(Exception)
|
35
|
+
lambda { Class.new(ExampleGroup).describe("context", :shared => true) }.should_not raise_error(Exception)
|
36
|
+
end
|
41
37
|
|
42
|
-
|
43
|
-
|
38
|
+
it "should return all shared example_groups" do
|
39
|
+
b1 = make_shared_example_group("b1", :shared => true) {}
|
40
|
+
b2 = make_shared_example_group("b2", :shared => true) {}
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
42
|
+
b1.should_not be(nil)
|
43
|
+
b2.should_not be(nil)
|
48
44
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
45
|
+
SharedExampleGroup.find_shared_example_group("b1").should equal(b1)
|
46
|
+
SharedExampleGroup.find_shared_example_group("b2").should equal(b2)
|
47
|
+
end
|
53
48
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
49
|
+
it "should register as shared example_group" do
|
50
|
+
example_group = make_shared_example_group("example_group") {}
|
51
|
+
SharedExampleGroup.shared_example_groups.should include(example_group)
|
52
|
+
end
|
58
53
|
|
59
|
-
|
60
|
-
|
54
|
+
it "should not be shared when not configured as shared" do
|
55
|
+
example_group = non_shared_example_group
|
56
|
+
SharedExampleGroup.shared_example_groups.should_not include(example_group)
|
61
57
|
end
|
62
|
-
|
58
|
+
|
59
|
+
it "should complain when adding a second shared example_group with the same description" do
|
63
60
|
describe "shared example_group", :shared => true do
|
64
61
|
end
|
65
|
-
|
66
|
-
|
62
|
+
lambda do
|
63
|
+
describe "shared example_group", :shared => true do
|
64
|
+
end
|
65
|
+
end.should raise_error(ArgumentError)
|
66
|
+
end
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
it "should NOT complain when adding the same shared example_group instance again" do
|
69
|
+
shared_example_group = Class.new(ExampleGroup).describe("shared example_group", :shared => true)
|
70
|
+
SharedExampleGroup.add_shared_example_group(shared_example_group)
|
71
|
+
SharedExampleGroup.add_shared_example_group(shared_example_group)
|
72
|
+
end
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
it "should NOT complain when adding the same shared example_group again (i.e. file gets reloaded)" do
|
75
|
+
lambda do
|
76
|
+
2.times do
|
77
|
+
describe "shared example_group which gets loaded twice", :shared => true do
|
78
|
+
end
|
78
79
|
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should NOT complain when adding the same shared example_group in same file with different absolute path" do
|
84
|
-
shared_example_group_1 = Class.new(ExampleGroup).describe(
|
85
|
-
"shared example_group",
|
86
|
-
:shared => true,
|
87
|
-
:spec_path => "/my/spec/a/../shared.rb"
|
88
|
-
)
|
89
|
-
shared_example_group_2 = Class.new(ExampleGroup).describe(
|
90
|
-
"shared example_group",
|
91
|
-
:shared => true,
|
92
|
-
:spec_path => "/my/spec/b/../shared.rb"
|
93
|
-
)
|
94
|
-
|
95
|
-
SharedExampleGroup.add_shared_example_group(shared_example_group_1)
|
96
|
-
SharedExampleGroup.add_shared_example_group(shared_example_group_2)
|
97
|
-
end
|
80
|
+
end.should_not raise_error(ArgumentError)
|
81
|
+
end
|
98
82
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
lambda do
|
83
|
+
it "should NOT complain when adding the same shared example_group in same file with different absolute path" do
|
84
|
+
shared_example_group_1 = Class.new(ExampleGroup).describe(
|
85
|
+
"shared example_group",
|
86
|
+
:shared => true,
|
87
|
+
:spec_path => "/my/spec/a/../shared.rb"
|
88
|
+
)
|
89
|
+
shared_example_group_2 = Class.new(ExampleGroup).describe(
|
90
|
+
"shared example_group",
|
91
|
+
:shared => true,
|
92
|
+
:spec_path => "/my/spec/b/../shared.rb"
|
93
|
+
)
|
94
|
+
|
95
|
+
SharedExampleGroup.add_shared_example_group(shared_example_group_1)
|
113
96
|
SharedExampleGroup.add_shared_example_group(shared_example_group_2)
|
114
|
-
end
|
115
|
-
end
|
97
|
+
end
|
116
98
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
99
|
+
it "should complain when adding a different shared example_group with the same name in a different file with the same basename" do
|
100
|
+
shared_example_group_1 = Class.new(ExampleGroup).describe(
|
101
|
+
"shared example_group",
|
102
|
+
:shared => true,
|
103
|
+
:spec_path => "/my/spec/a/shared.rb"
|
104
|
+
)
|
105
|
+
shared_example_group_2 = Class.new(ExampleGroup).describe(
|
106
|
+
"shared example_group",
|
107
|
+
:shared => true,
|
108
|
+
:spec_path => "/my/spec/b/shared.rb"
|
109
|
+
)
|
110
|
+
|
111
|
+
SharedExampleGroup.add_shared_example_group(shared_example_group_1)
|
112
|
+
lambda do
|
113
|
+
SharedExampleGroup.add_shared_example_group(shared_example_group_2)
|
114
|
+
end.should raise_error(ArgumentError, /already exists/)
|
121
115
|
end
|
122
116
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
117
|
+
it "should add examples to current example_group using it_should_behave_like" do
|
118
|
+
shared_example_group = make_shared_example_group("shared example_group") do
|
119
|
+
it("shared example") {}
|
120
|
+
it("shared example 2") {}
|
121
|
+
end
|
128
122
|
|
129
|
-
|
130
|
-
|
131
|
-
|
123
|
+
example_group.it("example") {}
|
124
|
+
example_group.number_of_examples.should == 1
|
125
|
+
example_group.it_should_behave_like("shared example_group")
|
126
|
+
example_group.number_of_examples.should == 3
|
132
127
|
end
|
133
|
-
|
134
|
-
example_group = describe "one thing" do
|
135
|
-
include shared_example_group
|
136
|
-
end
|
137
|
-
|
138
|
-
example_group.number_of_examples.should == 1
|
139
|
-
end
|
140
128
|
|
141
|
-
|
142
|
-
|
143
|
-
|
129
|
+
it "should add examples to from two shared groups" do
|
130
|
+
shared_example_group_1 = make_shared_example_group("shared example_group 1") do
|
131
|
+
it("shared example 1") {}
|
132
|
+
end
|
133
|
+
|
134
|
+
shared_example_group_1 = make_shared_example_group("shared example_group 2") do
|
135
|
+
it("shared example 2") {}
|
136
|
+
end
|
137
|
+
|
138
|
+
example_group.it("example") {}
|
139
|
+
example_group.number_of_examples.should == 1
|
140
|
+
example_group.it_should_behave_like("shared example_group 1", "shared example_group 2")
|
141
|
+
example_group.number_of_examples.should == 3
|
144
142
|
end
|
143
|
+
|
144
|
+
it "should add examples to current example_group using include" do
|
145
|
+
shared_example_group = describe "all things", :shared => true do
|
146
|
+
it "should do stuff" do end
|
147
|
+
end
|
145
148
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
+
example_group = describe "one thing" do
|
150
|
+
include shared_example_group
|
151
|
+
end
|
149
152
|
|
150
|
-
|
151
|
-
|
153
|
+
example_group.number_of_examples.should == 1
|
154
|
+
end
|
152
155
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
156
|
+
it "should add examples to current example_group using it_should_behave_like with a module" do
|
157
|
+
AllThings = describe "all things", :shared => true do
|
158
|
+
it "should do stuff" do end
|
159
|
+
end
|
160
|
+
|
161
|
+
example_group = describe "one thing" do
|
162
|
+
it_should_behave_like AllThings
|
163
|
+
end
|
164
|
+
|
165
|
+
example_group.number_of_examples.should == 1
|
157
166
|
end
|
158
167
|
|
159
|
-
|
168
|
+
it "should run shared examples" do
|
169
|
+
shared_example_ran = false
|
170
|
+
shared_example_group = make_shared_example_group("shared example_group") do
|
171
|
+
it("shared example") { shared_example_ran = true }
|
172
|
+
end
|
160
173
|
|
161
|
-
|
162
|
-
example_group.it("example") {example_ran = true}
|
163
|
-
example_group.run
|
164
|
-
example_ran.should be_true
|
165
|
-
shared_example_ran.should be_true
|
166
|
-
end
|
174
|
+
example_ran = false
|
167
175
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
after { shared_teardown_ran = true }
|
174
|
-
it("shared example") { shared_example_ran = true }
|
176
|
+
example_group.it_should_behave_like("shared example_group")
|
177
|
+
example_group.it("example") {example_ran = true}
|
178
|
+
example_group.run
|
179
|
+
example_ran.should be_true
|
180
|
+
shared_example_ran.should be_true
|
175
181
|
end
|
176
182
|
|
177
|
-
|
183
|
+
it "should run setup and teardown from shared example_group" do
|
184
|
+
shared_setup_ran = false
|
185
|
+
shared_teardown_ran = false
|
186
|
+
shared_example_group = make_shared_example_group("shared example_group") do
|
187
|
+
before { shared_setup_ran = true }
|
188
|
+
after { shared_teardown_ran = true }
|
189
|
+
it("shared example") { shared_example_ran = true }
|
190
|
+
end
|
178
191
|
|
179
|
-
|
180
|
-
example_group.it("example") {example_ran = true}
|
181
|
-
example_group.run
|
182
|
-
example_ran.should be_true
|
183
|
-
shared_setup_ran.should be_true
|
184
|
-
shared_teardown_ran.should be_true
|
185
|
-
end
|
192
|
+
example_ran = false
|
186
193
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
it("shared example") { shared_example_ran = true }
|
194
|
+
example_group.it_should_behave_like("shared example_group")
|
195
|
+
example_group.it("example") {example_ran = true}
|
196
|
+
example_group.run
|
197
|
+
example_ran.should be_true
|
198
|
+
shared_setup_ran.should be_true
|
199
|
+
shared_teardown_ran.should be_true
|
194
200
|
end
|
195
201
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
end
|
202
|
+
it "should run before(:all) and after(:all) only once from shared example_group" do
|
203
|
+
shared_before_all_run_count = 0
|
204
|
+
shared_after_all_run_count = 0
|
205
|
+
shared_example_group = make_shared_example_group("shared example_group") do
|
206
|
+
before(:all) { shared_before_all_run_count += 1}
|
207
|
+
after(:all) { shared_after_all_run_count += 1}
|
208
|
+
it("shared example") { shared_example_ran = true }
|
209
|
+
end
|
205
210
|
|
206
|
-
|
207
|
-
@formatter.should_receive(:add_example_group).with(any_args)
|
211
|
+
example_ran = false
|
208
212
|
|
209
|
-
|
210
|
-
it("
|
213
|
+
example_group.it_should_behave_like("shared example_group")
|
214
|
+
example_group.it("example") {example_ran = true}
|
215
|
+
example_group.run
|
216
|
+
example_ran.should be_true
|
217
|
+
shared_before_all_run_count.should == 1
|
218
|
+
shared_after_all_run_count.should == 1
|
211
219
|
end
|
212
220
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
221
|
+
it "should include modules, included into shared example_group, into current example_group" do
|
222
|
+
@formatter.should_receive(:add_example_group).with(any_args)
|
223
|
+
|
224
|
+
shared_example_group = make_shared_example_group("shared example_group") do
|
225
|
+
it("shared example") { shared_example_ran = true }
|
217
226
|
end
|
218
|
-
end
|
219
227
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
228
|
+
mod1_method_called = false
|
229
|
+
mod1 = Module.new do
|
230
|
+
define_method :mod1_method do
|
231
|
+
mod1_method_called = true
|
232
|
+
end
|
224
233
|
end
|
225
|
-
end
|
226
234
|
|
227
|
-
|
235
|
+
mod2_method_called = false
|
236
|
+
mod2 = Module.new do
|
237
|
+
define_method :mod2_method do
|
238
|
+
mod2_method_called = true
|
239
|
+
end
|
240
|
+
end
|
228
241
|
|
229
|
-
|
230
|
-
example_group.include mod1
|
242
|
+
shared_example_group.__send__ :include, mod2
|
231
243
|
|
232
|
-
|
233
|
-
|
234
|
-
mod2_method
|
235
|
-
end
|
236
|
-
example_group.run
|
237
|
-
mod1_method_called.should be_true
|
238
|
-
mod2_method_called.should be_true
|
239
|
-
end
|
244
|
+
example_group.it_should_behave_like("shared example_group")
|
245
|
+
example_group.include mod1
|
240
246
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
"this got defined in a shared example_group"
|
247
|
+
example_group.it("test") do
|
248
|
+
mod1_method
|
249
|
+
mod2_method
|
245
250
|
end
|
251
|
+
example_group.run
|
252
|
+
mod1_method_called.should be_true
|
253
|
+
mod2_method_called.should be_true
|
246
254
|
end
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
255
|
+
|
256
|
+
it "should make methods defined in the shared example_group available in consuming example_group" do
|
257
|
+
shared_example_group = make_shared_example_group("shared example_group xyz") do
|
258
|
+
def a_shared_helper_method
|
259
|
+
"this got defined in a shared example_group"
|
260
|
+
end
|
261
|
+
end
|
262
|
+
example_group.it_should_behave_like("shared example_group xyz")
|
263
|
+
success = false
|
264
|
+
example_group.it("should access a_shared_helper_method") do
|
265
|
+
a_shared_helper_method
|
266
|
+
success = true
|
267
|
+
end
|
268
|
+
example_group.run
|
269
|
+
success.should be_true
|
252
270
|
end
|
253
|
-
example_group.run
|
254
|
-
success.should be_true
|
255
|
-
end
|
256
271
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
272
|
+
it "should raise when named shared example_group can not be found" do
|
273
|
+
lambda {
|
274
|
+
example_group.it_should_behave_like("non-existent shared example group")
|
275
|
+
violated
|
276
|
+
}.should raise_error("Shared Example Group 'non-existent shared example group' can not be found")
|
277
|
+
end
|
262
278
|
end
|
263
279
|
end
|
264
280
|
end
|