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
@@ -7,33 +7,33 @@ module Spec
7
7
  attr_accessor :examples_ran
8
8
  end
9
9
 
10
- @@klass_variable_set = true
11
- CONSTANT = :foobar
10
+ @@class_variable = :class_variable
11
+ CONSTANT = :constant
12
12
 
13
13
  before do
14
- @instance_variable = :hello
14
+ @instance_variable = :instance_variable
15
15
  end
16
-
17
- it "should run" do
16
+
17
+ after(:all) do
18
18
  self.class.examples_ran = true
19
19
  end
20
20
 
21
21
  it "should have access to instance variables" do
22
- @instance_variable.should == :hello
22
+ @instance_variable.should == :instance_variable
23
23
  end
24
24
 
25
25
  it "should have access to class variables" do
26
- @@klass_variable_set.should == true
26
+ @@class_variable.should == :class_variable
27
27
  end
28
28
 
29
29
  it "should have access to constants" do
30
- CONSTANT.should == :foobar
30
+ CONSTANT.should == :constant
31
31
  end
32
32
 
33
33
  it "should have access to methods defined in the Example Group" do
34
34
  a_method.should == 22
35
35
  end
36
-
36
+
37
37
  def a_method
38
38
  22
39
39
  end
@@ -6,34 +6,34 @@ module Spec
6
6
  describe "#get" do
7
7
  attr_reader :example_group
8
8
  before do
9
- @example_group = Class.new(ExampleGroup)
10
- ExampleGroupFactory.register(:registered_type, @example_group)
9
+ @example_group_class = Class.new(ExampleGroup)
10
+ ExampleGroupFactory.register(:registered_type, @example_group_class)
11
11
  end
12
12
 
13
13
  after do
14
14
  ExampleGroupFactory.reset
15
15
  end
16
16
 
17
- it "should #get the default ExampleGroup type when passed nil" do
17
+ it "should return the default ExampleGroup type for nil" do
18
18
  ExampleGroupFactory.get(nil).should == ExampleGroup
19
19
  end
20
20
 
21
- it "should #get the default ExampleGroup for unregistered non-nil values" do
21
+ it "should return the default ExampleGroup for an unregistered non-nil value" do
22
22
  ExampleGroupFactory.get(:does_not_exist).should == ExampleGroup
23
23
  end
24
24
 
25
- it "should #get custom type for :registered_type" do
26
- ExampleGroupFactory.get(:registered_type).should == @example_group
25
+ it "should return custom type if registered" do
26
+ ExampleGroupFactory.get(:registered_type).should == @example_group_class
27
27
  end
28
28
 
29
- it "should #get the actual type when that is passed in" do
30
- ExampleGroupFactory.get(@example_group).should == @example_group
29
+ it "should return the actual type when that is what is submitted" do
30
+ ExampleGroupFactory.get(@example_group_class).should == @example_group_class
31
31
  end
32
32
 
33
33
  it "should get the custom type after setting the default" do
34
- @example_group2 = Class.new(ExampleGroup)
35
- ExampleGroupFactory.default(@example_group2)
36
- ExampleGroupFactory.get(:registered_type).should == @example_group
34
+ @alternate_example_group_class = Class.new(ExampleGroup)
35
+ ExampleGroupFactory.default(@alternate_example_group_class)
36
+ ExampleGroupFactory.get(:registered_type).should == @example_group_class
37
37
  end
38
38
  end
39
39
 
@@ -57,15 +57,8 @@ module Spec
57
57
  example_group.superclass.should == Spec::Example::ExampleGroup
58
58
  end
59
59
 
60
- describe "when :type => :default" do
61
- it "should create a Spec::Example::Example" do
62
- example_group = Spec::Example::ExampleGroupFactory.create_example_group(
63
- "example_group", :type => :default
64
- ) {}
65
- example_group.superclass.should == Spec::Example::ExampleGroup
66
- end
67
-
68
- it "should create a Spec::Example::Example" do
60
+ describe "with :type => :default" do
61
+ it "should create a Spec::Example::ExampleGroup" do
69
62
  example_group = Spec::Example::ExampleGroupFactory.create_example_group(
70
63
  "example_group", :type => :default
71
64
  ) {}
@@ -73,8 +66,8 @@ module Spec
73
66
  end
74
67
  end
75
68
 
76
- describe "when :type => :something_other_than_default" do
77
- it "should create specified type" do
69
+ describe "with :type => :something_other_than_default" do
70
+ it "should create the specified type" do
78
71
  Spec::Example::ExampleGroupFactory.register(:something_other_than_default, parent_example_group)
79
72
  non_default_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
80
73
  "example_group", :type => :something_other_than_default
@@ -100,15 +93,14 @@ module Spec
100
93
  custom_example_group.superclass.should == parent_example_group
101
94
  end
102
95
 
103
- describe "when :shared => true" do
104
- attr_reader :shared_example_group
105
- before do
106
- @shared_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
96
+ describe "with :shared => true" do
97
+ def shared_example_group
98
+ @shared_example_group ||= Spec::Example::ExampleGroupFactory.create_example_group(
107
99
  "name", :spec_path => '/blah/spec/models/blah.rb', :type => :controller, :shared => true
108
100
  ) {}
109
101
  end
110
102
 
111
- it "should create and register a Spec::Example::Example" do
103
+ it "should create and register a Spec::Example::SharedExampleGroup" do
112
104
  shared_example_group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
113
105
  SharedExampleGroup.shared_example_groups.should include(shared_example_group)
114
106
  end
@@ -139,6 +131,35 @@ module Spec
139
131
  Spec::Example::ExampleGroupFactory.reset
140
132
  end
141
133
  end
134
+
135
+ describe "#all_registered?" do
136
+ before(:each) do
137
+ @unregistered_parent = Class.new(ExampleGroup)
138
+ @registered_child = Class.new(@unregistered_parent)
139
+ @unregistered_grandchild = Class.new(@registered_child)
140
+ Spec::Example::ExampleGroupFactory.register :registered_child, @registered_child
141
+ end
142
+
143
+ it "should return true for empty list" do
144
+ Spec::Example::ExampleGroupFactory.all_registered?([]).should be_true
145
+ end
146
+
147
+ it "should return true for a registered example group class" do
148
+ Spec::Example::ExampleGroupFactory.all_registered?([@registered_child]).should be_true
149
+ end
150
+
151
+ it "should return true for an ancestor of a registered example_group_classes" do
152
+ Spec::Example::ExampleGroupFactory.all_registered?([@unregistered_parent]).should be_true
153
+ end
154
+
155
+ it "should return false for a subclass of a registered example_group_class" do
156
+ Spec::Example::ExampleGroupFactory.all_registered?([@unregistered_grandchild]).should be_false
157
+ end
158
+
159
+ after(:each) do
160
+ Spec::Example::ExampleGroupFactory.reset
161
+ end
162
+ end
142
163
  end
143
164
  end
144
165
  end
@@ -3,569 +3,579 @@ require File.dirname(__FILE__) + '/../../spec_helper'
3
3
  module Spec
4
4
  module Example
5
5
  describe 'ExampleGroupMethods' do
6
- include SandboxedOptions
7
- attr_reader :example_group, :result, :reporter
8
- before(:each) do
9
- # See http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/525-arity-changed-on-partial-mocks#ticket-525-2
10
- method_with_three_args = lambda { |arg1, arg2, arg3| }
11
- options.formatters << mock("formatter", :null_object => true, :example_pending => method_with_three_args)
12
- options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
13
- @reporter = FakeReporter.new(@options)
14
- options.reporter = reporter
15
- @example_group = Class.new(ExampleGroup) do
16
- describe("ExampleGroup")
17
- it "does nothing"
18
- end
19
- class << example_group
20
- public :include
6
+ with_sandboxed_options do
7
+ attr_reader :example_group, :result, :reporter
8
+ before(:each) do
9
+ # See http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/525-arity-changed-on-partial-mocks#ticket-525-2
10
+ method_with_three_args = lambda { |arg1, arg2, arg3| }
11
+ options.formatters << mock("formatter", :null_object => true, :example_pending => method_with_three_args)
12
+ options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
13
+ @reporter = FakeReporter.new(@options)
14
+ options.reporter = reporter
15
+ @example_group = Class.new(ExampleGroup) do
16
+ describe("ExampleGroup")
17
+ it "does nothing"
18
+ end
19
+ class << example_group
20
+ public :include
21
+ end
22
+ @result = nil
21
23
  end
22
- @result = nil
23
- end
24
24
 
25
- after(:each) do
26
- ExampleGroup.reset
27
- end
25
+ after(:each) do
26
+ ExampleGroup.reset
27
+ end
28
28
 
29
- ["describe","context"].each do |method|
30
- describe "#{method}" do
31
- describe "when creating an ExampleGroup" do
32
- attr_reader :child_example_group
33
- before do
34
- @child_example_group = @example_group.send method, "Another ExampleGroup" do
35
- it "should pass" do
36
- true.should be_true
29
+ ["describe","context"].each do |method|
30
+ describe "##{method}" do
31
+ describe "when creating an ExampleGroup" do
32
+ attr_reader :child_example_group
33
+ before do
34
+ @child_example_group = @example_group.send method, "Another ExampleGroup" do
35
+ it "should pass" do
36
+ true.should be_true
37
+ end
37
38
  end
38
39
  end
39
- end
40
40
 
41
- it "should create a subclass of the ExampleGroup when passed a block" do
42
- child_example_group.superclass.should == @example_group
43
- @options.example_groups.should include(child_example_group)
44
- end
41
+ it "should create a subclass of the ExampleGroup when passed a block" do
42
+ child_example_group.superclass.should == @example_group
43
+ @options.example_groups.should include(child_example_group)
44
+ end
45
45
 
46
- it "should not inherit examples" do
47
- child_example_group.examples.length.should == 1
46
+ it "should not inherit examples" do
47
+ child_example_group.examples.length.should == 1
48
+ end
48
49
  end
49
- end
50
50
 
51
- describe "when creating a SharedExampleGroup" do
52
- attr_reader :name, :shared_example_group
53
- before do
54
- @name = "A Shared ExampleGroup"
55
- @shared_example_group = @example_group.send method, name, :shared => true do
56
- it "should pass" do
57
- true.should be_true
51
+ describe "when creating a SharedExampleGroup" do
52
+ attr_reader :name, :shared_example_group
53
+ before do
54
+ @name = "A Shared ExampleGroup"
55
+ @shared_example_group = @example_group.send method, name, :shared => true do
56
+ it "should pass" do
57
+ true.should be_true
58
+ end
58
59
  end
59
60
  end
60
- end
61
61
 
62
- after do
63
- SharedExampleGroup.shared_example_groups.delete_if do |registered_shared_example_group|
64
- registered_shared_example_group == shared_example_group
62
+ after do
63
+ SharedExampleGroup.shared_example_groups.delete_if do |registered_shared_example_group|
64
+ registered_shared_example_group == shared_example_group
65
+ end
65
66
  end
66
- end
67
67
 
68
- it "should create a SharedExampleGroup" do
69
- SharedExampleGroup.find_shared_example_group(name).should == shared_example_group
68
+ it "should create a SharedExampleGroup" do
69
+ SharedExampleGroup.find_shared_example_group(name).should == shared_example_group
70
+ end
70
71
  end
71
- end
72
72
 
73
+ end
73
74
  end
74
- end
75
75
 
76
- describe "#it" do
77
- it "should should create an example instance" do
78
- lambda {
79
- @example_group.it("")
80
- }.should change { @example_group.examples.length }.by(1)
76
+ describe "#it" do
77
+ it "should should create an example instance" do
78
+ lambda {
79
+ @example_group.it("")
80
+ }.should change { @example_group.examples.length }.by(1)
81
+ end
81
82
  end
82
- end
83
83
 
84
- describe "#xit and #xspecify" do
85
- before(:each) do
86
- Kernel.stub!(:warn)
87
- end
84
+ describe "#xit and #xspecify" do
85
+ before(:each) do
86
+ Kernel.stub!(:warn)
87
+ end
88
88
 
89
- it "should NOT create an example instance" do
90
- lambda {
91
- @example_group.xit("")
92
- }.should_not change(@example_group.examples, :length)
89
+ it "should NOT create an example instance" do
90
+ lambda {
91
+ @example_group.xit("")
92
+ }.should_not change(@example_group.examples, :length)
93
93
 
94
- lambda {
95
- @example_group.xspecify("")
96
- }.should_not change(@example_group.examples, :length)
97
- end
94
+ lambda {
95
+ @example_group.xspecify("")
96
+ }.should_not change(@example_group.examples, :length)
97
+ end
98
98
 
99
- it "should warn that it is disabled" do
100
- Kernel.should_receive(:warn).with("Example disabled: foo").twice
101
- @example_group.xit("foo")
102
- @example_group.xspecify("foo")
99
+ it "should warn that it is disabled" do
100
+ Kernel.should_receive(:warn).with("Example disabled: foo").twice
101
+ @example_group.xit("foo")
102
+ @example_group.xspecify("foo")
103
+ end
103
104
  end
104
- end
105
105
 
106
- describe "#examples" do
107
- it "should have Examples" do
108
- example_group = Class.new(ExampleGroup) do
109
- describe('example')
110
- it "should pass" do
111
- 1.should == 1
106
+ describe "#examples" do
107
+ it "should have Examples" do
108
+ example_group = Class.new(ExampleGroup) do
109
+ describe('example')
110
+ it "should pass" do
111
+ 1.should == 1
112
+ end
112
113
  end
114
+ example_group.examples.length.should == 1
115
+ example_group.examples.first.description.should == "should pass"
113
116
  end
114
- example_group.examples.length.should == 1
115
- example_group.examples.first.description.should == "should pass"
116
- end
117
117
 
118
- it "should not include methods that begin with test (only when TU interop is loaded)" do
119
- example_group = Class.new(ExampleGroup) do
120
- describe('example')
121
- def test_any_args(*args)
122
- true.should be_true
123
- end
124
- def test_something
125
- 1.should == 1
126
- end
127
- def test
128
- raise "This is not a real test"
129
- end
130
- def testify
131
- raise "This is not a real test"
132
- end
133
- def should_something
134
- # forces the run
118
+ it "should not include methods that begin with test (only when TU interop is loaded)" do
119
+ example_group = Class.new(ExampleGroup) do
120
+ describe('example')
121
+ def test_any_args(*args)
122
+ true.should be_true
123
+ end
124
+ def test_something
125
+ 1.should == 1
126
+ end
127
+ def test
128
+ raise "This is not a real test"
129
+ end
130
+ def testify
131
+ raise "This is not a real test"
132
+ end
133
+ def should_something
134
+ # forces the run
135
+ end
135
136
  end
137
+ example_group.examples.length.should == 1
138
+ example_group.run.should be_true
136
139
  end
137
- example_group.examples.length.should == 1
138
- example_group.run.should be_true
139
- end
140
140
 
141
- it "should include methods that begin with should and has an arity of 0 in suite" do
142
- example_group = Class.new(ExampleGroup) do
143
- describe('example')
144
- def shouldCamelCase
145
- true.should be_true
146
- end
147
- def should_any_args(*args)
148
- true.should be_true
149
- end
150
- def should_something
151
- 1.should == 1
152
- end
153
- def should_not_something
154
- 1.should_not == 2
155
- end
156
- def should
157
- raise "This is not a real example"
141
+ it "should include methods that begin with should and has an arity of 0 in suite" do
142
+ example_group = Class.new(ExampleGroup) do
143
+ describe('example')
144
+ def shouldCamelCase
145
+ true.should be_true
146
+ end
147
+ def should_any_args(*args)
148
+ true.should be_true
149
+ end
150
+ def should_something
151
+ 1.should == 1
152
+ end
153
+ def should_not_something
154
+ 1.should_not == 2
155
+ end
156
+ def should
157
+ raise "This is not a real example"
158
+ end
159
+ def should_not
160
+ raise "This is not a real example"
161
+ end
158
162
  end
159
- def should_not
160
- raise "This is not a real example"
163
+ example_group = example_group.dup
164
+ example_group.examples.length.should == 4
165
+ descriptions = example_group.examples.collect {|example| example.description}.sort
166
+ descriptions.should include("shouldCamelCase")
167
+ descriptions.should include("should_any_args")
168
+ descriptions.should include("should_something")
169
+ descriptions.should include("should_not_something")
170
+ descriptions.should_not include("should")
171
+ descriptions.should_not include("should_not")
172
+ end
173
+
174
+ it "should not include methods that begin with test_ and has an arity > 0 in suite" do
175
+ example_group = Class.new(ExampleGroup) do
176
+ describe('example')
177
+ def test_invalid(foo)
178
+ 1.should == 1
179
+ end
180
+ def testInvalidCamelCase(foo)
181
+ 1.should == 1
182
+ end
161
183
  end
184
+ example_group.examples.length.should == 0
162
185
  end
163
- example_group = example_group.dup
164
- example_group.examples.length.should == 4
165
- descriptions = example_group.examples.collect {|example| example.description}.sort
166
- descriptions.should include("shouldCamelCase")
167
- descriptions.should include("should_any_args")
168
- descriptions.should include("should_something")
169
- descriptions.should include("should_not_something")
170
- end
171
186
 
172
- it "should not include methods that begin with test_ and has an arity > 0 in suite" do
173
- example_group = Class.new(ExampleGroup) do
174
- describe('example')
175
- def test_invalid(foo)
176
- 1.should == 1
177
- end
178
- def testInvalidCamelCase(foo)
179
- 1.should == 1
187
+ it "should not include methods that begin with should_ and has an arity > 0 in suite" do
188
+ example_group = Class.new(ExampleGroup) do
189
+ describe('example')
190
+ def should_invalid(foo)
191
+ 1.should == 2
192
+ end
193
+ def shouldInvalidCamelCase(foo)
194
+ 1.should == 3
195
+ end
196
+ def should_not_invalid(foo)
197
+ 1.should == 4
198
+ end
199
+ def should_valid
200
+ 1.should == 1
201
+ end
180
202
  end
203
+ example_group.examples.length.should == 1
204
+ example_group.run.should be_true
181
205
  end
182
- example_group.examples.length.should == 0
183
- end
184
206
 
185
- it "should not include methods that begin with should_ and has an arity > 0 in suite" do
186
- example_group = Class.new(ExampleGroup) do
187
- describe('example')
188
- def should_invalid(foo)
189
- 1.should == 2
190
- end
191
- def shouldInvalidCamelCase(foo)
192
- 1.should == 3
193
- end
194
- def should_not_invalid(foo)
195
- 1.should == 4
196
- end
197
- def should_valid
198
- 1.should == 1
207
+ it "should run should_methods" do
208
+ example_group = Class.new(ExampleGroup) do
209
+ def should_valid
210
+ 1.should == 2
211
+ end
199
212
  end
213
+ example_group.examples.length.should == 1
214
+ example_group.run.should be_false
200
215
  end
201
- example_group.examples.length.should == 1
202
- example_group.run.should be_true
203
216
  end
204
217
 
205
- it "should run should_methods" do
206
- example_group = Class.new(ExampleGroup) do
207
- def should_valid
208
- 1.should == 2
218
+ describe "#set_description" do
219
+ attr_reader :example_group
220
+ before do
221
+ class << example_group
222
+ public :set_description
209
223
  end
210
224
  end
211
- example_group.examples.length.should == 1
212
- example_group.run.should be_false
213
- end
214
- end
215
225
 
216
- describe "#set_description" do
217
- attr_reader :example_group
218
- before do
219
- class << example_group
220
- public :set_description
221
- end
222
- end
226
+ describe "#set_description(String)" do
227
+ before(:each) do
228
+ example_group.set_description("abc")
229
+ end
223
230
 
224
- describe "#set_description(String)" do
225
- before(:each) do
226
- example_group.set_description("abc")
227
- end
231
+ specify ".description should return the String passed into .set_description" do
232
+ example_group.description.should == "abc"
233
+ end
228
234
 
229
- specify ".description should return the String passed into .set_description" do
230
- example_group.description.should == "abc"
235
+ specify ".described_type should provide nil as its type" do
236
+ example_group.described_type.should be_nil
237
+ end
231
238
  end
232
239
 
233
- specify ".described_type should provide nil as its type" do
234
- example_group.described_type.should be_nil
235
- end
236
- end
240
+ describe "#set_description(Type)" do
241
+ before(:each) do
242
+ example_group.set_description(ExampleGroup)
243
+ end
237
244
 
238
- describe "#set_description(Type)" do
239
- before(:each) do
240
- example_group.set_description(ExampleGroup)
241
- end
245
+ specify ".description should return a String representation of that type (fully qualified) as its name" do
246
+ example_group.description.should == "Spec::Example::ExampleGroup"
247
+ end
242
248
 
243
- specify ".description should return a String representation of that type (fully qualified) as its name" do
244
- example_group.description.should == "Spec::Example::ExampleGroup"
249
+ specify ".described_type should return the passed in type" do
250
+ example_group.described_type.should == Spec::Example::ExampleGroup
251
+ end
245
252
  end
246
253
 
247
- specify ".described_type should return the passed in type" do
248
- example_group.described_type.should == Spec::Example::ExampleGroup
249
- end
250
- end
254
+ describe "#set_description(String, Type)" do
255
+ before(:each) do
256
+ example_group.set_description("behaving", ExampleGroup)
257
+ end
251
258
 
252
- describe "#set_description(String, Type)" do
253
- before(:each) do
254
- example_group.set_description("behaving", ExampleGroup)
255
- end
259
+ specify ".description should return String then space then Type" do
260
+ example_group.description.should == "behaving Spec::Example::ExampleGroup"
261
+ end
256
262
 
257
- specify ".description should return String then space then Type" do
258
- example_group.description.should == "behaving Spec::Example::ExampleGroup"
263
+ specify ".described_type should return the passed in type" do
264
+ example_group.described_type.should == Spec::Example::ExampleGroup
265
+ end
259
266
  end
260
267
 
261
- specify ".described_type should return the passed in type" do
262
- example_group.described_type.should == Spec::Example::ExampleGroup
263
- end
264
- end
268
+ describe "#set_description(Type, String not starting with a space)" do
269
+ before(:each) do
270
+ example_group.set_description(ExampleGroup, "behaving")
271
+ end
265
272
 
266
- describe "#set_description(Type, String not starting with a space)" do
267
- before(:each) do
268
- example_group.set_description(ExampleGroup, "behaving")
273
+ specify ".description should return the Type then space then String" do
274
+ example_group.description.should == "Spec::Example::ExampleGroup behaving"
275
+ end
269
276
  end
270
277
 
271
- specify ".description should return the Type then space then String" do
272
- example_group.description.should == "Spec::Example::ExampleGroup behaving"
273
- end
274
- end
278
+ describe "#set_description(Type, String starting with .)" do
279
+ before(:each) do
280
+ example_group.set_description(ExampleGroup, ".behaving")
281
+ end
275
282
 
276
- describe "#set_description(Type, String starting with .)" do
277
- before(:each) do
278
- example_group.set_description(ExampleGroup, ".behaving")
283
+ specify ".description should return the Type then String" do
284
+ example_group.description.should == "Spec::Example::ExampleGroup.behaving"
285
+ end
279
286
  end
280
287
 
281
- specify ".description should return the Type then String" do
282
- example_group.description.should == "Spec::Example::ExampleGroup.behaving"
283
- end
284
- end
288
+ describe "#set_description(Type, String containing .)" do
289
+ before(:each) do
290
+ example_group.set_description(ExampleGroup, "calling a.b")
291
+ end
285
292
 
286
- describe "#set_description(Type, String containing .)" do
287
- before(:each) do
288
- example_group.set_description(ExampleGroup, "calling a.b")
293
+ specify ".description should return the Type then space then String" do
294
+ example_group.description.should == "Spec::Example::ExampleGroup calling a.b"
295
+ end
289
296
  end
290
297
 
291
- specify ".description should return the Type then space then String" do
292
- example_group.description.should == "Spec::Example::ExampleGroup calling a.b"
293
- end
294
- end
298
+ describe "#set_description(Type, String starting with .)" do
299
+ before(:each) do
300
+ example_group.set_description(ExampleGroup, ".behaving")
301
+ end
295
302
 
296
- describe "#set_description(Type, String starting with .)" do
297
- before(:each) do
298
- example_group.set_description(ExampleGroup, ".behaving")
303
+ specify "should return the Type then String" do
304
+ example_group.description.should == "Spec::Example::ExampleGroup.behaving"
305
+ end
299
306
  end
300
307
 
301
- specify "should return the Type then String" do
302
- example_group.description.should == "Spec::Example::ExampleGroup.behaving"
303
- end
304
- end
308
+ describe "#set_description(Type, String containing .)" do
309
+ before(:each) do
310
+ example_group.set_description(ExampleGroup, "is #1")
311
+ end
305
312
 
306
- describe "#set_description(Type, String containing .)" do
307
- before(:each) do
308
- example_group.set_description(ExampleGroup, "is #1")
313
+ specify ".description should return the Type then space then String" do
314
+ example_group.description.should == "Spec::Example::ExampleGroup is #1"
315
+ end
309
316
  end
310
317
 
311
- specify ".description should return the Type then space then String" do
312
- example_group.description.should == "Spec::Example::ExampleGroup is #1"
313
- end
314
- end
318
+ describe "#set_description(String, Type, String)" do
319
+ before(:each) do
320
+ example_group.set_description("A", Hash, "with one entry")
321
+ end
315
322
 
316
- describe "#set_description(String, Type, String)" do
317
- before(:each) do
318
- example_group.set_description("A", Hash, "with one entry")
323
+ specify ".description should return the first String then space then Type then second String" do
324
+ example_group.description.should == "A Hash with one entry"
325
+ end
319
326
  end
320
327
 
321
- specify ".description should return the first String then space then Type then second String" do
322
- example_group.description.should == "A Hash with one entry"
323
- end
324
- end
328
+ describe "#set_description(Hash representing options)" do
329
+ before(:each) do
330
+ example_group.set_description(:a => "b", :spec_path => "blah")
331
+ end
325
332
 
326
- describe "#set_description(Hash representing options)" do
327
- before(:each) do
328
- example_group.set_description(:a => "b", :spec_path => "blah")
329
- end
333
+ it ".spec_path should expand the passed in :spec_path option passed into the constructor" do
334
+ example_group.spec_path.should == File.expand_path("blah")
335
+ end
330
336
 
331
- it ".spec_path should expand the passed in :spec_path option passed into the constructor" do
332
- example_group.spec_path.should == File.expand_path("blah")
333
- end
337
+ it ".description_options should return all the options passed in" do
338
+ example_group.description_options.should == {:a => "b", :spec_path => "blah"}
339
+ end
334
340
 
335
- it ".description_options should return all the options passed in" do
336
- example_group.description_options.should == {:a => "b", :spec_path => "blah"}
337
341
  end
338
-
339
342
  end
340
- end
341
343
 
342
- describe "#description" do
343
- it "should return the same description instance for each call" do
344
- example_group.description.should eql(example_group.description)
345
- end
344
+ describe "#description" do
345
+ it "should return the same description instance for each call" do
346
+ example_group.description.should eql(example_group.description)
347
+ end
346
348
 
347
- it "should not add a space when description_text begins with #" do
348
- child_example_group = Class.new(example_group) do
349
- describe("#foobar", "Does something")
349
+ it "should not add a space when description_text begins with #" do
350
+ child_example_group = Class.new(example_group) do
351
+ describe("#foobar", "Does something")
352
+ end
353
+ child_example_group.description.should == "ExampleGroup#foobar Does something"
350
354
  end
351
- child_example_group.description.should == "ExampleGroup#foobar Does something"
352
- end
353
355
 
354
- it "should not add a space when description_text begins with ." do
355
- child_example_group = Class.new(example_group) do
356
- describe(".foobar", "Does something")
356
+ it "should not add a space when description_text begins with ." do
357
+ child_example_group = Class.new(example_group) do
358
+ describe(".foobar", "Does something")
359
+ end
360
+ child_example_group.description.should == "ExampleGroup.foobar Does something"
357
361
  end
358
- child_example_group.description.should == "ExampleGroup.foobar Does something"
359
- end
360
362
 
361
- it "should return the class name if nil" do
362
- example_group.set_description(nil)
363
- example_group.description.should =~ /Class:/
364
- end
363
+ it "should return the class name if nil" do
364
+ example_group.set_description(nil)
365
+ example_group.description.should =~ /Class:/
366
+ end
365
367
 
366
- it "should return the class name if nil" do
367
- example_group.set_description("")
368
- example_group.description.should =~ /Class:/
368
+ it "should return the class name if nil" do
369
+ example_group.set_description("")
370
+ example_group.description.should =~ /Class:/
371
+ end
369
372
  end
370
- end
371
373
 
372
- describe "#description_parts" do
373
- it "should return an Array of the current class description args" do
374
- example_group.description_parts.should == [example_group.description]
375
- end
374
+ describe "#description_parts" do
375
+ it "should return an Array of the current class description args" do
376
+ example_group.description_parts.should == [example_group.description]
377
+ end
376
378
 
377
- it "should return an Array of the description args from each class in the hierarchy" do
378
- child_example_group = Class.new(example_group)
379
- child_example_group.describe("Child", ExampleGroup)
380
- child_example_group.description.should_not be_empty
381
-
382
- grand_child_example_group = Class.new(child_example_group)
383
- grand_child_example_group.describe("GrandChild", ExampleGroup)
384
- grand_child_example_group.description.should_not be_empty
385
-
386
- grand_child_example_group.description_parts.should == [
387
- "ExampleGroup",
388
- "Child",
389
- Spec::Example::ExampleGroup,
390
- "GrandChild",
391
- Spec::Example::ExampleGroup
392
- ]
393
- end
394
- end
379
+ it "should return an Array of the description args from each class in the hierarchy" do
380
+ child_example_group = Class.new(example_group)
381
+ child_example_group.describe("Child", ExampleGroup)
382
+ child_example_group.description.should_not be_empty
395
383
 
396
- describe "#described_type" do
397
- it "should return passed in type" do
398
- child_example_group = Class.new(example_group) do
399
- describe Object
384
+ grand_child_example_group = Class.new(child_example_group)
385
+ grand_child_example_group.describe("GrandChild", ExampleGroup)
386
+ grand_child_example_group.description.should_not be_empty
387
+
388
+ grand_child_example_group.description_parts.should == [
389
+ "ExampleGroup",
390
+ "Child",
391
+ Spec::Example::ExampleGroup,
392
+ "GrandChild",
393
+ Spec::Example::ExampleGroup
394
+ ]
400
395
  end
401
- child_example_group.described_type.should == Object
402
396
  end
403
397
 
404
- it "should return #described_type of superclass when no passed in type" do
405
- parent_example_group = Class.new(ExampleGroup) do
406
- describe Object, "#foobar"
398
+ describe "#described_type" do
399
+ it "should return passed in type" do
400
+ child_example_group = Class.new(example_group) do
401
+ describe Object
402
+ end
403
+ child_example_group.described_type.should == Object
407
404
  end
408
- child_example_group = Class.new(parent_example_group) do
409
- describe "not a type"
405
+
406
+ it "should return #described_type of superclass when no passed in type" do
407
+ parent_example_group = Class.new(ExampleGroup) do
408
+ describe Object, "#foobar"
409
+ end
410
+ child_example_group = Class.new(parent_example_group) do
411
+ describe "not a type"
412
+ end
413
+ child_example_group.described_type.should == Object
410
414
  end
411
- child_example_group.described_type.should == Object
412
415
  end
413
- end
414
416
 
415
- describe "#remove_after" do
416
- it "should unregister a given after(:each) block" do
417
- after_all_ran = false
418
- @example_group.it("example") {}
419
- proc = Proc.new { after_all_ran = true }
420
- ExampleGroup.after(:each, &proc)
421
- @example_group.run
422
- after_all_ran.should be_true
423
-
424
- after_all_ran = false
425
- ExampleGroup.remove_after(:each, &proc)
426
- @example_group.run
427
- after_all_ran.should be_false
417
+ describe "#remove_after" do
418
+ it "should unregister a given after(:each) block" do
419
+ after_all_ran = false
420
+ @example_group.it("example") {}
421
+ proc = Proc.new { after_all_ran = true }
422
+ ExampleGroup.after(:each, &proc)
423
+ @example_group.run
424
+ after_all_ran.should be_true
425
+
426
+ after_all_ran = false
427
+ ExampleGroup.remove_after(:each, &proc)
428
+ @example_group.run
429
+ after_all_ran.should be_false
430
+ end
428
431
  end
429
- end
430
432
 
431
- describe "#include" do
432
- it "should have accessible class methods from included module" do
433
- mod1_method_called = false
434
- mod1 = Module.new do
435
- extend Spec::MetaClass
436
- class_methods = Module.new do
437
- define_method :mod1_method do
438
- mod1_method_called = true
433
+ describe "#include" do
434
+ it "should have accessible class methods from included module" do
435
+ mod1_method_called = false
436
+ mod1 = Module.new do
437
+ extend Spec::MetaClass
438
+ class_methods = Module.new do
439
+ define_method :mod1_method do
440
+ mod1_method_called = true
441
+ end
439
442
  end
440
- end
441
443
 
442
- metaclass.class_eval do
443
- define_method(:included) do |receiver|
444
- receiver.extend class_methods
444
+ metaclass.class_eval do
445
+ define_method(:included) do |receiver|
446
+ receiver.extend class_methods
447
+ end
445
448
  end
446
449
  end
447
- end
448
450
 
449
- mod2_method_called = false
450
- mod2 = Module.new do
451
- extend Spec::MetaClass
452
- class_methods = Module.new do
453
- define_method :mod2_method do
454
- mod2_method_called = true
451
+ mod2_method_called = false
452
+ mod2 = Module.new do
453
+ extend Spec::MetaClass
454
+ class_methods = Module.new do
455
+ define_method :mod2_method do
456
+ mod2_method_called = true
457
+ end
455
458
  end
456
- end
457
459
 
458
- metaclass.class_eval do
459
- define_method(:included) do |receiver|
460
- receiver.extend class_methods
460
+ metaclass.class_eval do
461
+ define_method(:included) do |receiver|
462
+ receiver.extend class_methods
463
+ end
461
464
  end
462
465
  end
463
- end
464
466
 
465
- @example_group.include mod1, mod2
467
+ @example_group.include mod1, mod2
466
468
 
467
- @example_group.mod1_method
468
- @example_group.mod2_method
469
- mod1_method_called.should be_true
470
- mod2_method_called.should be_true
469
+ @example_group.mod1_method
470
+ @example_group.mod2_method
471
+ mod1_method_called.should be_true
472
+ mod2_method_called.should be_true
473
+ end
471
474
  end
472
- end
473
475
 
474
- describe "#number_of_examples" do
475
- it "should count number of specs" do
476
- proc do
477
- @example_group.it("one") {}
478
- @example_group.it("two") {}
479
- @example_group.it("three") {}
480
- @example_group.it("four") {}
481
- end.should change {@example_group.number_of_examples}.by(4)
476
+ describe "#number_of_examples" do
477
+ it "should count number of specs" do
478
+ proc do
479
+ @example_group.it("one") {}
480
+ @example_group.it("two") {}
481
+ @example_group.it("three") {}
482
+ @example_group.it("four") {}
483
+ end.should change {@example_group.number_of_examples}.by(4)
484
+ end
482
485
  end
483
- end
484
486
 
485
- describe "#class_eval" do
486
- it "should allow constants to be defined" do
487
- example_group = Class.new(ExampleGroup) do
488
- describe('example')
489
- FOO = 1
490
- it "should reference FOO" do
491
- FOO.should == 1
487
+ describe "#class_eval" do
488
+ it "should allow constants to be defined" do
489
+ example_group = Class.new(ExampleGroup) do
490
+ describe('example')
491
+ FOO = 1
492
+ it "should reference FOO" do
493
+ FOO.should == 1
494
+ end
492
495
  end
496
+ example_group.run
497
+ Object.const_defined?(:FOO).should == false
493
498
  end
494
- example_group.run
495
- Object.const_defined?(:FOO).should == false
496
499
  end
497
- end
498
500
 
499
- describe '#register' do
500
- it "should add ExampleGroup to set of ExampleGroups to be run" do
501
- options.example_groups.delete(example_group)
502
- options.example_groups.should_not include(example_group)
501
+ describe '#register' do
502
+ it "should add ExampleGroup to set of ExampleGroups to be run" do
503
+ options.example_groups.delete(example_group)
504
+ options.example_groups.should_not include(example_group)
503
505
 
504
- example_group.register {}
505
- options.example_groups.should include(example_group)
506
+ example_group.register {}
507
+ options.example_groups.should include(example_group)
508
+ end
506
509
  end
507
- end
508
510
 
509
- describe '#unregister' do
510
- before do
511
- options.example_groups.should include(example_group)
512
- end
511
+ describe '#unregister' do
512
+ before do
513
+ options.example_groups.should include(example_group)
514
+ end
513
515
 
514
- it "should remove ExampleGroup from set of ExampleGroups to be run" do
515
- example_group.unregister
516
- options.example_groups.should_not include(example_group)
516
+ it "should remove ExampleGroup from set of ExampleGroups to be run" do
517
+ example_group.unregister
518
+ options.example_groups.should_not include(example_group)
519
+ end
517
520
  end
518
- end
519
521
 
520
- describe "#registration_backtrace" do
521
- it "returns the backtrace of where the ExampleGroup was registered" do
522
- example_group = Class.new(ExampleGroup)
523
- example_group.registration_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-1}")
522
+ describe "#registration_backtrace" do
523
+ it "returns the backtrace of where the ExampleGroup was registered" do
524
+ example_group = Class.new(ExampleGroup)
525
+ example_group.registration_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-1}")
526
+ end
524
527
  end
525
- end
526
528
 
527
- describe "#run" do
528
- it "should add_example_group if there are any examples to run" do
529
- example_group = Class.new(ExampleGroup) do
530
- it "should do something" do end
529
+ describe "#run" do
530
+ it "should add_example_group if there are any examples to run" do
531
+ example_group = Class.new(ExampleGroup) do
532
+ it "should do something" do end
533
+ end
534
+ reporter.should_receive(:add_example_group)
535
+ example_group.run
531
536
  end
532
- reporter.should_receive(:add_example_group)
533
- example_group.run
534
- end
535
537
 
536
- it "should NOT add_example_group if there are no examples to run" do
537
- example_group = Class.new(ExampleGroup) do end
538
- reporter.should_not_receive(:add_example_group)
539
- example_group.run
538
+ it "should NOT add_example_group if there are no examples to run" do
539
+ example_group = Class.new(ExampleGroup) do end
540
+ reporter.should_not_receive(:add_example_group)
541
+ example_group.run
542
+ end
540
543
  end
541
- end
542
544
 
543
- describe "#matcher_class=" do
544
- it "should call new and matches? on the class used for matching examples" do
545
- example_group = Class.new(ExampleGroup) do
546
- it "should do something" do end
547
- class << self
548
- def specified_examples
549
- ["something"]
550
- end
551
- def to_s
552
- "TestMatcher"
545
+ describe "#matcher_class=" do
546
+ it "should call new and matches? on the class used for matching examples" do
547
+ example_group = Class.new(ExampleGroup) do
548
+ it "should do something" do end
549
+ class << self
550
+ def specified_examples
551
+ ["something"]
552
+ end
553
+ def to_s
554
+ "TestMatcher"
555
+ end
553
556
  end
554
557
  end
555
- end
556
558
 
557
- matcher = mock("matcher")
558
- matcher.should_receive(:matches?).with(["something"]).any_number_of_times
559
+ matcher = mock("matcher")
560
+ matcher.should_receive(:matches?).with(["something"]).any_number_of_times
559
561
 
560
- matcher_class = Class.new
561
- matcher_class.should_receive(:new).with("TestMatcher", "should do something").twice.and_return(matcher)
562
+ matcher_class = Class.new
563
+ matcher_class.should_receive(:new).with("TestMatcher", "should do something").twice.and_return(matcher)
562
564
 
563
- begin
564
- ExampleGroupMethods.matcher_class = matcher_class
565
+ begin
566
+ ExampleGroupMethods.matcher_class = matcher_class
565
567
 
566
- example_group.run
567
- ensure
568
- ExampleGroupMethods.matcher_class = ExampleMatcher
568
+ example_group.run
569
+ ensure
570
+ ExampleGroupMethods.matcher_class = ExampleMatcher
571
+ end
572
+ end
573
+ end
574
+
575
+ describe "#options" do
576
+ it "should expose the options hash" do
577
+ group = describe("group", :this => 'hash') {}
578
+ group.options[:this].should == 'hash'
569
579
  end
570
580
  end
571
581
  end