rspec 1.1.8 → 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/History.txt +30 -3
  2. data/License.txt +22 -0
  3. data/Manifest.txt +3 -3
  4. data/README.txt +1 -25
  5. data/Rakefile +4 -2
  6. data/TODO.txt +5 -4
  7. data/bin/autospec +1 -1
  8. data/examples/pure/shared_example_group_example.rb +2 -2
  9. data/lib/autotest/rspec.rb +1 -1
  10. data/lib/spec.rb +5 -1
  11. data/lib/spec/example.rb +1 -1
  12. data/lib/spec/example/before_and_after_hooks.rb +93 -0
  13. data/lib/spec/example/configuration.rb +10 -1
  14. data/lib/spec/example/example_group.rb +2 -1
  15. data/lib/spec/example/example_group_factory.rb +18 -1
  16. data/lib/spec/example/example_group_methods.rb +45 -123
  17. data/lib/spec/example/example_methods.rb +9 -6
  18. data/lib/spec/example/shared_example_group.rb +6 -12
  19. data/lib/spec/extensions/main.rb +1 -1
  20. data/lib/spec/interop/test/unit/testcase.rb +1 -1
  21. data/lib/spec/mocks/error_generator.rb +1 -1
  22. data/lib/spec/mocks/message_expectation.rb +19 -4
  23. data/lib/spec/mocks/methods.rb +2 -2
  24. data/lib/spec/mocks/proxy.rb +4 -5
  25. data/lib/spec/runner.rb +3 -4
  26. data/lib/spec/runner/formatter/nested_text_formatter.rb +3 -3
  27. data/lib/spec/runner/option_parser.rb +23 -22
  28. data/lib/spec/version.rb +1 -1
  29. data/rspec.gemspec +19 -8
  30. data/spec/autotest/rspec_spec.rb +5 -1
  31. data/spec/spec/example/configuration_spec.rb +229 -215
  32. data/spec/spec/example/example_group_class_definition_spec.rb +9 -9
  33. data/spec/spec/example/example_group_factory_spec.rb +48 -27
  34. data/spec/spec/example/example_group_methods_spec.rb +436 -426
  35. data/spec/spec/example/example_group_spec.rb +459 -500
  36. data/spec/spec/example/example_methods_spec.rb +92 -86
  37. data/spec/spec/example/shared_example_group_spec.rb +219 -203
  38. data/spec/spec/extensions/main_spec.rb +23 -23
  39. data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +13 -0
  40. data/spec/spec/interop/test/unit/spec_spec.rb +15 -8
  41. data/spec/spec/mocks/mock_spec.rb +12 -2
  42. data/spec/spec/mocks/nil_expectation_warning_spec.rb +0 -1
  43. data/spec/spec/mocks/partial_mock_spec.rb +10 -5
  44. data/spec/spec/package/bin_spec_spec.rb +8 -0
  45. data/spec/spec/runner/command_line_spec.rb +101 -100
  46. data/spec/spec/runner/drb_command_line_spec.rb +0 -2
  47. data/spec/spec/runner/formatter/html_formatter_spec.rb +1 -4
  48. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +230 -245
  49. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -3
  50. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +110 -109
  51. data/spec/spec/runner/option_parser_spec.rb +18 -6
  52. data/spec/spec_helper.rb +26 -5
  53. data/stories/mock_framework_integration/use_flexmock.story +1 -1
  54. metadata +38 -7
  55. data/lib/spec/example/module_inclusion_warnings.rb +0 -38
  56. data/spec/spec/example/example_group/described_module_spec.rb +0 -20
  57. 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
- before do
26
- @original_rspec_options = Spec::Runner.options
27
- @options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
28
- Spec::Runner.use @options
29
- @options.formatters << mock("formatter", :null_object => true)
30
- @options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
31
- @reporter = FakeReporter.new(@options)
32
- @options.reporter = @reporter
33
-
34
- ExampleMethods.before_all_parts.should == []
35
- ExampleMethods.before_each_parts.should == []
36
- ExampleMethods.after_each_parts.should == []
37
- ExampleMethods.after_all_parts.should == []
38
- def ExampleMethods.count
39
- @count ||= 0
40
- @count = @count + 1
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
- it "should pass before and after callbacks to all ExampleGroup subclasses" do
54
- ExampleMethods.before(:suite) do
55
- ExampleMethods.count.should == 1
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
- ExampleMethods.before(:all) do
59
- ExampleMethods.count.should == 2
60
- end
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
- ExampleMethods.before(:each) do
63
- ExampleMethods.count.should == 3
64
- end
55
+ ExampleGroup.before(:all) do
56
+ ExampleGroup.count.should == 2
57
+ end
65
58
 
66
- ExampleMethods.after(:each) do
67
- ExampleMethods.count.should == 4
68
- end
59
+ ExampleGroup.before(:each) do
60
+ ExampleGroup.count.should == 3
61
+ end
69
62
 
70
- ExampleMethods.after(:all) do
71
- ExampleMethods.count.should == 5
72
- end
63
+ ExampleGroup.after(:each) do
64
+ ExampleGroup.count.should == 4
65
+ end
73
66
 
74
- ExampleMethods.after(:suite) do
75
- ExampleMethods.count.should == 6
76
- end
67
+ ExampleGroup.after(:all) do
68
+ ExampleGroup.count.should == 5
69
+ end
77
70
 
78
- @example_group = Class.new(ExampleGroup) do
79
- it "should use ExampleMethods callbacks" do
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
- describe "eval_block" do
87
- before(:each) do
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 "with no given description" do
100
- it "should provide the generated description" do
101
- @example = @example_group.it { 2.should == 2 }
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
- describe "with no implementation" do
108
- it "should raise an NotYetImplementedError" do
109
- lambda {
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
- }.should raise_error(Spec::Example::NotYetImplementedError, "Not Yet Implemented")
91
+ @example.description.should == "given description"
92
+ end
113
93
  end
114
-
115
- def extract_error(&blk)
116
- begin
117
- blk.call
118
- rescue Exception => e
119
- return e
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
- it "should use the proper file and line number for the NotYetImplementedError" do
126
- file = __FILE__
127
- line_number = __LINE__ + 3
111
+ def extract_error(&blk)
112
+ begin
113
+ blk.call
114
+ rescue Exception => e
115
+ return e
116
+ end
128
117
 
129
- error = extract_error do
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
- error.pending_caller.should == "#{file}:#{line_number}"
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
- include SandboxedOptions
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
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
- after(:each) do
18
- @formatter.rspec_verify
19
- @example_group = nil
20
- $shared_example_groups.clear unless $shared_example_groups.nil?
21
- end
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
- def non_shared_example_group()
30
- @non_shared_example_group ||= Class.new(ExampleGroup).describe("example_group")
31
- end
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
- 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
29
+ def non_shared_example_group()
30
+ @non_shared_example_group ||= Class.new(ExampleGroup).describe("example_group")
31
+ end
37
32
 
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) {}
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
- b1.should_not be(nil)
43
- b2.should_not be(nil)
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
- SharedExampleGroup.find_shared_example_group("b1").should equal(b1)
46
- SharedExampleGroup.find_shared_example_group("b2").should equal(b2)
47
- end
42
+ b1.should_not be(nil)
43
+ b2.should_not be(nil)
48
44
 
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
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
- 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)
57
- end
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
- it "should complain when adding a second shared example_group with the same description" do
60
- describe "shared example_group", :shared => true do
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
- lambda do
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
- end.should raise_error(ArgumentError)
66
- end
62
+ lambda do
63
+ describe "shared example_group", :shared => true do
64
+ end
65
+ end.should raise_error(ArgumentError)
66
+ end
67
67
 
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
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
- 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
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.should_not raise_error(ArgumentError)
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
- 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
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.should raise_error(ArgumentError, /already exists/)
115
- end
97
+ end
116
98
 
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") {}
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
- 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
127
- end
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
- it "should add examples to current example_group using include" do
130
- shared_example_group = describe "all things", :shared => true do
131
- it "should do stuff" do end
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
- it "should add examples to current example_group using it_should_behave_like with a module" do
142
- AllThings = describe "all things", :shared => true do
143
- it "should do stuff" do end
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
- example_group = describe "one thing" do
147
- it_should_behave_like AllThings
148
- end
149
+ example_group = describe "one thing" do
150
+ include shared_example_group
151
+ end
149
152
 
150
- example_group.number_of_examples.should == 1
151
- end
153
+ example_group.number_of_examples.should == 1
154
+ end
152
155
 
153
- it "should run shared examples" do
154
- shared_example_ran = false
155
- shared_example_group = make_shared_example_group("shared example_group") do
156
- it("shared example") { shared_example_ran = true }
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
- example_ran = false
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
- example_group.it_should_behave_like("shared example_group")
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
- it "should run setup and teardown from shared example_group" do
169
- shared_setup_ran = false
170
- shared_teardown_ran = false
171
- shared_example_group = make_shared_example_group("shared example_group") do
172
- before { shared_setup_ran = true }
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
- example_ran = false
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
- example_group.it_should_behave_like("shared example_group")
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
- it "should run before(:all) and after(:all) only once from shared example_group" do
188
- shared_before_all_run_count = 0
189
- shared_after_all_run_count = 0
190
- shared_example_group = make_shared_example_group("shared example_group") do
191
- before(:all) { shared_before_all_run_count += 1}
192
- after(:all) { shared_after_all_run_count += 1}
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
- example_ran = false
197
-
198
- example_group.it_should_behave_like("shared example_group")
199
- example_group.it("example") {example_ran = true}
200
- example_group.run
201
- example_ran.should be_true
202
- shared_before_all_run_count.should == 1
203
- shared_after_all_run_count.should == 1
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
- it "should include modules, included into shared example_group, into current example_group" do
207
- @formatter.should_receive(:add_example_group).with(any_args)
211
+ example_ran = false
208
212
 
209
- shared_example_group = make_shared_example_group("shared example_group") do
210
- it("shared example") { shared_example_ran = true }
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
- mod1_method_called = false
214
- mod1 = Module.new do
215
- define_method :mod1_method do
216
- mod1_method_called = true
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
- mod2_method_called = false
221
- mod2 = Module.new do
222
- define_method :mod2_method do
223
- mod2_method_called = true
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
- shared_example_group.include mod2
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
- example_group.it_should_behave_like("shared example_group")
230
- example_group.include mod1
242
+ shared_example_group.__send__ :include, mod2
231
243
 
232
- example_group.it("test") do
233
- mod1_method
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
- it "should make methods defined in the shared example_group available in consuming example_group" do
242
- shared_example_group = make_shared_example_group("shared example_group xyz") do
243
- def a_shared_helper_method
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
- example_group.it_should_behave_like("shared example_group xyz")
248
- success = false
249
- example_group.it("should access a_shared_helper_method") do
250
- a_shared_helper_method
251
- success = true
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
- it "should raise when named shared example_group can not be found" do
258
- lambda {
259
- example_group.it_should_behave_like("non-existent shared example group")
260
- violated
261
- }.should raise_error("Shared Example Group 'non-existent shared example group' can not be found")
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