rspec-core 2.7.1 → 2.8.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/README.md +1 -1
  2. data/features/command_line/order.feature +29 -0
  3. data/features/command_line/tag.feature +10 -9
  4. data/features/configuration/default_path.feature +2 -2
  5. data/features/filtering/exclusion_filters.feature +1 -1
  6. data/features/filtering/run_all_when_everything_filtered.feature +1 -1
  7. data/features/subject/attribute_of_subject.feature +1 -1
  8. data/lib/rspec/core.rb +148 -12
  9. data/lib/rspec/core/command_line.rb +2 -2
  10. data/lib/rspec/core/configuration.rb +300 -155
  11. data/lib/rspec/core/configuration_options.rb +34 -53
  12. data/lib/rspec/core/deprecation.rb +4 -0
  13. data/lib/rspec/core/drb_options.rb +72 -0
  14. data/lib/rspec/core/example.rb +58 -24
  15. data/lib/rspec/core/example_group.rb +10 -5
  16. data/lib/rspec/core/extensions.rb +1 -0
  17. data/lib/rspec/core/extensions/ordered.rb +16 -0
  18. data/lib/rspec/core/filter_manager.rb +170 -0
  19. data/lib/rspec/core/formatters/base_formatter.rb +3 -1
  20. data/lib/rspec/core/formatters/base_text_formatter.rb +6 -0
  21. data/lib/rspec/core/formatters/snippet_extractor.rb +1 -1
  22. data/lib/rspec/core/hooks.rb +197 -1
  23. data/lib/rspec/core/let.rb +3 -2
  24. data/lib/rspec/core/metadata.rb +25 -4
  25. data/lib/rspec/core/option_parser.rb +89 -54
  26. data/lib/rspec/core/pending.rb +41 -0
  27. data/lib/rspec/core/rake_task.rb +9 -25
  28. data/lib/rspec/core/reporter.rb +43 -19
  29. data/lib/rspec/core/shared_context.rb +35 -0
  30. data/lib/rspec/core/shared_example_group.rb +0 -1
  31. data/lib/rspec/core/subject.rb +4 -4
  32. data/lib/rspec/core/version.rb +1 -1
  33. data/lib/rspec/core/world.rb +34 -52
  34. data/spec/autotest/failed_results_re_spec.rb +2 -2
  35. data/spec/command_line/order_spec.rb +131 -0
  36. data/spec/rspec/core/command_line_spec.rb +2 -1
  37. data/spec/rspec/core/configuration_options_spec.rb +83 -163
  38. data/spec/rspec/core/configuration_spec.rb +311 -139
  39. data/spec/rspec/core/drb_options_spec.rb +131 -0
  40. data/spec/rspec/core/example_group_spec.rb +22 -11
  41. data/spec/rspec/core/example_spec.rb +1 -2
  42. data/spec/rspec/core/filter_manager_spec.rb +175 -0
  43. data/spec/rspec/core/formatters/helpers_spec.rb +1 -1
  44. data/spec/rspec/core/formatters/html_formatter_spec.rb +3 -2
  45. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +1 -1
  46. data/spec/rspec/core/metadata_spec.rb +21 -6
  47. data/spec/rspec/core/option_parser_spec.rb +74 -0
  48. data/spec/rspec/core/reporter_spec.rb +18 -1
  49. data/spec/rspec/core/shared_context_spec.rb +54 -17
  50. data/spec/rspec/core/subject_spec.rb +1 -1
  51. data/spec/rspec/core/world_spec.rb +7 -188
  52. data/spec/spec_helper.rb +47 -43
  53. data/spec/support/config_options_helper.rb +27 -0
  54. metadata +28 -12
  55. data/lib/rspec/core/expecting/with_rspec.rb +0 -9
  56. data/lib/rspec/core/expecting/with_stdlib.rb +0 -9
@@ -16,7 +16,7 @@ module RSpec
16
16
 
17
17
  let(:generated_html) do
18
18
  options = RSpec::Core::ConfigurationOptions.new(
19
- %w[spec/rspec/core/resources/formatter_specs.rb --format textmate]
19
+ %w[spec/rspec/core/resources/formatter_specs.rb --format textmate --order default]
20
20
  )
21
21
  options.parse_options
22
22
  err, out = StringIO.new, StringIO.new
@@ -22,7 +22,6 @@ module RSpec
22
22
  end
23
23
 
24
24
  describe "#filter_applies?" do
25
-
26
25
  let(:parent_group_metadata) { Metadata.new.process('parent group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
27
26
  let(:group_metadata) { Metadata.new(parent_group_metadata).process('group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
28
27
  let(:example_metadata) { group_metadata.for_example('example', :caller => ["foo_spec.rb:#{__LINE__}"], :if => true) }
@@ -313,13 +312,29 @@ module RSpec
313
312
  child.for_example('example', child)[:full_description].should eq("parent child example")
314
313
  end
315
314
 
315
+ it "concats nested example group descriptions three deep" do
316
+ grandparent = Metadata.new
317
+ grandparent.process('grandparent')
318
+
319
+ parent = Metadata.new(grandparent)
320
+ parent.process('parent')
321
+
322
+ child = Metadata.new(parent)
323
+ child.process('child')
324
+
325
+ grandparent[:example_group][:full_description].should eq("grandparent")
326
+ parent[:example_group][:full_description].should eq("grandparent parent")
327
+ child[:example_group][:full_description].should eq("grandparent parent child")
328
+ child.for_example('example', child)[:full_description].should eq("grandparent parent child example")
329
+ end
330
+
316
331
  %w[# . ::].each do |char|
317
332
  context "with a 2nd arg starting with #{char}" do
318
- it "removes the space" do
319
- m = Metadata.new
320
- m.process(Array, "#{char}method")
321
- m[:example_group][:full_description].should eq("Array#{char}method")
322
- end
333
+ it "removes the space" do
334
+ m = Metadata.new
335
+ m.process(Array, "#{char}method")
336
+ m[:example_group][:full_description].should eq("Array#{char}method")
337
+ end
323
338
  end
324
339
  end
325
340
 
@@ -82,5 +82,79 @@ module RSpec::Core
82
82
  end
83
83
  end
84
84
 
85
+ %w[--tag -t].each do |option|
86
+ describe option do
87
+ context "without ~" do
88
+ it "treats no value as true" do
89
+ options = Parser.parse!([option, 'foo'])
90
+ options[:inclusion_filter].should eq(:foo => true)
91
+ end
92
+
93
+ it "treats 'true' as true" do
94
+ options = Parser.parse!([option, 'foo:true'])
95
+ options[:inclusion_filter].should eq(:foo => true)
96
+ end
97
+
98
+ it "treats 'nil' as nil" do
99
+ options = Parser.parse!([option, 'foo:nil'])
100
+ options[:inclusion_filter].should eq(:foo => nil)
101
+ end
102
+
103
+ it "treats 'false' as false" do
104
+ options = Parser.parse!([option, 'foo:false'])
105
+ options[:inclusion_filter].should eq(:foo => false)
106
+ end
107
+
108
+ it "merges muliple invocations" do
109
+ options = Parser.parse!([option, 'foo:false', option, 'bar:true', option, 'foo:true'])
110
+ options[:inclusion_filter].should eq(:foo => true, :bar => true)
111
+ end
112
+ end
113
+
114
+ context "with ~" do
115
+ it "treats no value as true" do
116
+ options = Parser.parse!([option, '~foo'])
117
+ options[:exclusion_filter].should eq(:foo => true)
118
+ end
119
+
120
+ it "treats 'true' as true" do
121
+ options = Parser.parse!([option, '~foo:true'])
122
+ options[:exclusion_filter].should eq(:foo => true)
123
+ end
124
+
125
+ it "treats 'nil' as nil" do
126
+ options = Parser.parse!([option, '~foo:nil'])
127
+ options[:exclusion_filter].should eq(:foo => nil)
128
+ end
129
+
130
+ it "treats 'false' as false" do
131
+ options = Parser.parse!([option, '~foo:false'])
132
+ options[:exclusion_filter].should eq(:foo => false)
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ describe "--order" do
139
+ it "is nil by default" do
140
+ Parser.parse!([])[:order].should be_nil
141
+ end
142
+
143
+ %w[rand random].each do |option|
144
+ context "with #{option}" do
145
+ it "defines the order as random" do
146
+ options = Parser.parse!(['--order', option])
147
+ options[:order].should eq(option)
148
+ end
149
+ end
150
+ end
151
+ end
152
+
153
+ describe "--seed" do
154
+ it "sets the order to rand:SEED" do
155
+ options = Parser.parse!(%w[--seed 123])
156
+ options[:order].should eq("rand:123")
157
+ end
158
+ end
85
159
  end
86
160
  end
@@ -10,7 +10,7 @@ module RSpec::Core
10
10
  %w[start_dump dump_pending dump_failures dump_summary close].each do |message|
11
11
  it "sends #{message} to the formatter(s)" do
12
12
  formatter.should_receive(message)
13
- reporter.abort
13
+ reporter.abort(nil)
14
14
  end
15
15
  end
16
16
  end
@@ -82,5 +82,22 @@ module RSpec::Core
82
82
  reporter.example_started(example)
83
83
  end
84
84
  end
85
+
86
+ describe "#report" do
87
+ it "supports one arg (count)" do
88
+ Reporter.new.report(1) {}
89
+ end
90
+
91
+ it "supports two args (count, seed)" do
92
+ Reporter.new.report(1, 2) {}
93
+ end
94
+
95
+ it "yields itself" do
96
+ reporter = Reporter.new
97
+ yielded = nil
98
+ reporter.report(3) {|r| yielded = r}
99
+ yielded.should eq(reporter)
100
+ end
101
+ end
85
102
  end
86
103
  end
@@ -1,30 +1,67 @@
1
1
  require "spec_helper"
2
2
 
3
- describe RSpec::Core::SharedContext do
4
- describe "hooks" do
5
- it "creates a before hook" do
6
- before_all_hook = false
7
- before_each_hook = false
8
- after_each_hook = false
9
- after_all_hook = false
3
+ describe RSpec::SharedContext do
4
+ it "is accessible as RSpec::Core::SharedContext" do
5
+ RSpec::Core::SharedContext
6
+ end
7
+
8
+ it "is accessible as RSpec::SharedContext" do
9
+ RSpec::SharedContext
10
+ end
11
+
12
+ it "supports before and after hooks" do
13
+ before_all_hook = false
14
+ before_each_hook = false
15
+ after_each_hook = false
16
+ after_all_hook = false
17
+ shared = Module.new do
18
+ extend RSpec::SharedContext
19
+ before(:all) { before_all_hook = true }
20
+ before(:each) { before_each_hook = true }
21
+ after(:each) { after_each_hook = true }
22
+ after(:all) { after_all_hook = true }
23
+ end
24
+ group = RSpec::Core::ExampleGroup.describe do
25
+ include shared
26
+ example { }
27
+ end
28
+
29
+ group.run
30
+
31
+ before_all_hook.should be_true
32
+ before_each_hook.should be_true
33
+ after_each_hook.should be_true
34
+ after_all_hook.should be_true
35
+ end
36
+
37
+ it "supports let" do
38
+ shared = Module.new do
39
+ extend RSpec::SharedContext
40
+ let(:foo) { 'foo' }
41
+ end
42
+ group = RSpec::Core::ExampleGroup.describe do
43
+ include shared
44
+ end
45
+
46
+ group.new.foo.should eq('foo')
47
+ end
48
+
49
+ %w[describe context].each do |method_name|
50
+ it "supports nested example groups using #{method_name}" do
10
51
  shared = Module.new do
11
- extend RSpec::Core::SharedContext
12
- before(:all) { before_all_hook = true }
13
- before(:each) { before_each_hook = true }
14
- after(:each) { after_each_hook = true }
15
- after(:all) { after_all_hook = true }
52
+ extend RSpec::SharedContext
53
+ send(method_name, "nested using describe") do
54
+ example {}
55
+ end
16
56
  end
17
57
  group = RSpec::Core::ExampleGroup.describe do
18
58
  include shared
19
- example { }
20
59
  end
21
60
 
22
61
  group.run
23
62
 
24
- before_all_hook.should be_true
25
- before_each_hook.should be_true
26
- after_each_hook.should be_true
27
- after_all_hook.should be_true
63
+ group.children.length.should eq(1)
64
+ group.children.first.examples.length.should eq(1)
28
65
  end
29
66
  end
30
67
  end
@@ -152,7 +152,7 @@ module RSpec::Core
152
152
  its([:a]) { should eq("Symbol: a") }
153
153
  its(['a']) { should eq("String: a") }
154
154
  its([:b, 'c', 4]) { should eq("Symbol: b; String: c; Fixnum: 4") }
155
- its(:name) { should = "George" }
155
+ its(:name) { should eq("George") }
156
156
  context "when referring to an attribute without the proper array syntax" do
157
157
  context "it raises an error" do
158
158
  its(:age) do
@@ -17,138 +17,11 @@ module RSpec::Core
17
17
  end
18
18
  end
19
19
 
20
- describe "#apply_inclusion_filters" do
21
- let(:group1) {
22
- RSpec::Core::ExampleGroup.describe(Bar, "find group-1",
23
- { :foo => 1, :color => 'blue', :feature => 'reporting' }
24
- ) {}
25
- }
26
-
27
- let(:group2) {
28
- RSpec::Core::ExampleGroup.describe(Bar, "find group-2",
29
- { :pending => true, :feature => 'reporting' }
30
- ) {}
31
- }
32
-
33
- let(:group3) {
34
- RSpec::Core::ExampleGroup.describe(Bar, "find group-3",
35
- { :array => [1,2,3,4], :color => 'blue' }
36
- ) {}
37
- }
38
-
39
- let(:group4) {
40
- RSpec::Core::ExampleGroup.describe(Foo, "find these examples") do
41
- it('I have no options') {}
42
- it("this is awesome", :awesome => true) {}
43
- it("this is too", :awesome => true) {}
44
- it("not so awesome", :awesome => false) {}
45
- it("I also have no options") {}
46
- end
47
- }
48
-
49
- let(:example_groups) { [group1, group2, group3, group4] }
50
-
51
- it "finds no groups when given no search parameters" do
52
- world.apply_inclusion_filters([],{}).should eq([])
53
- end
54
-
55
- it "finds matching groups when filtering on :describes (described class or module)" do
56
- world.apply_inclusion_filters(example_groups, :example_group => { :describes => Bar }).should eq([group1, group2, group3])
57
- end
58
-
59
- it "finds matching groups when filtering on :description with text" do
60
- world.apply_inclusion_filters(example_groups, :example_group => { :description => 'Bar find group-1' }).should eq([group1])
61
- end
62
-
63
- it "finds matching groups when filtering on :description with a lambda" do
64
- world.apply_inclusion_filters(example_groups, :example_group => { :description => lambda { |v| v.include?('-1') || v.include?('-3') } }).should eq([group1, group3])
65
- end
66
-
67
- it "finds matching groups when filtering on :description with a regular expression" do
68
- world.apply_inclusion_filters(example_groups, :example_group => { :description => /find group/ }).should eq([group1, group2, group3])
69
- end
70
-
71
- it "finds one group when searching for :pending => true" do
72
- world.apply_inclusion_filters(example_groups, :pending => true ).should eq([group2])
73
- end
74
-
75
- it "finds matching groups when filtering on arbitrary metadata with a number" do
76
- world.apply_inclusion_filters(example_groups, :foo => 1 ).should eq([group1])
77
- end
78
-
79
- it "finds matching groups when filtering on arbitrary metadata with an array" do
80
- world.apply_inclusion_filters(example_groups, :array => [1,2,3,4]).should eq([group3])
81
- end
82
-
83
- it "finds no groups when filtering on arbitrary metadata with an array but the arrays do not match" do
84
- world.apply_inclusion_filters(example_groups, :array => [4,3,2,1]).should be_empty
85
- end
86
-
87
- it "finds matching examples when filtering on arbitrary metadata" do
88
- world.apply_inclusion_filters(group4.examples, :awesome => true).should eq([group4.examples[1], group4.examples[2]])
89
- end
90
-
91
- it "finds matching examples for example that match any of the filters" do
92
- world.apply_inclusion_filters(group4.examples, :awesome => true, :something => :else).should eq([group4.examples[1], group4.examples[2]])
93
- end
94
- end
95
-
96
- describe "#apply_exclusion_filters" do
97
-
98
- it "finds nothing if all describes match the exclusion filter" do
99
- options = { :network_access => true }
100
-
101
- group1 = ExampleGroup.describe(Bar, "find group-1", options) do
102
- it("foo") {}
103
- it("bar") {}
104
- end
105
-
106
- world.register(group1)
107
-
108
- world.apply_exclusion_filters(group1.examples, :network_access => true).should eq([])
109
-
110
- group2 = ExampleGroup.describe(Bar, "find group-1") do
111
- it("foo", :network_access => true) {}
112
- it("bar") {}
113
- end
114
-
115
- world.register(group2)
116
-
117
- world.apply_exclusion_filters(group2.examples, :network_access => true).should eq([group2.examples.last])
118
- end
119
-
120
- it "finds nothing if a regexp matches the exclusion filter" do
121
- group = ExampleGroup.describe(Bar, "find group-1", :name => "exclude me with a regex", :another => "foo") do
122
- it("foo") {}
123
- it("bar") {}
124
- end
125
- world.register(group)
126
- world.apply_exclusion_filters(group.examples, :name => /exclude/).should eq([])
127
- world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo").should eq([])
128
- world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo", :example_group => {
129
- :describes => lambda { |b| b == Bar } } ).should eq([])
130
-
131
- world.apply_exclusion_filters(group.examples, :name => /exclude not/).should eq(group.examples)
132
- world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo").should eq([])
133
- world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo1").should eq([])
134
- end
135
-
136
- it "finds all if filters are empty" do
137
- group = ExampleGroup.describe(Bar) do
138
- example("foo") {}
139
- example("bar") {}
140
- end
141
- world.register(group)
142
- world.apply_exclusion_filters(group.examples, {}).should eq(group.examples)
143
- end
144
- end
145
-
146
20
  describe "#preceding_declaration_line (again)" do
147
-
148
21
  let(:group) do
149
22
  RSpec::Core::ExampleGroup.describe("group") do
150
23
 
151
- example("example") {}
24
+ example("example") {}
152
25
 
153
26
  end
154
27
  end
@@ -219,9 +92,9 @@ module RSpec::Core
219
92
 
220
93
  context "with an inclusion filter" do
221
94
  it "announces" do
222
- configuration.inclusion_filter = { :foo => 'bar' }
95
+ configuration.filter_run_including :foo => 'bar'
223
96
  reporter.should_receive(:message).
224
- with("No examples matched #{{ :foo => 'bar' }.inspect}.")
97
+ with(/All examples were filtered out/)
225
98
  world.announce_filters
226
99
  end
227
100
  end
@@ -229,18 +102,18 @@ module RSpec::Core
229
102
  context "with an inclusion filter and run_all_when_everything_filtered" do
230
103
  it "announces" do
231
104
  configuration.stub(:run_all_when_everything_filtered?) { true }
232
- configuration.inclusion_filter = { :foo => 'bar' }
105
+ configuration.filter_run_including :foo => 'bar'
233
106
  reporter.should_receive(:message).
234
- with("No examples matched #{{ :foo => 'bar' }.inspect}. Running all.")
107
+ with(/All examples were filtered out/)
235
108
  world.announce_filters
236
109
  end
237
110
  end
238
111
 
239
112
  context "with an exclusion filter" do
240
113
  it "announces" do
241
- configuration.exclusion_filter = { :foo => 'bar' }
114
+ configuration.filter_run_excluding :foo => 'bar'
242
115
  reporter.should_receive(:message).
243
- with("No examples were matched. Perhaps #{{ :foo => 'bar' }.inspect} is excluding everything?")
116
+ with(/All examples were filtered out/)
244
117
  world.announce_filters
245
118
  end
246
119
  end
@@ -257,59 +130,5 @@ module RSpec::Core
257
130
  end
258
131
  end
259
132
  end
260
-
261
- describe "#inclusion_filter" do
262
- describe "#description" do
263
- it 'cleans up the description' do
264
- # check the assumptions of this example
265
- project_dir = File.expand_path('.')
266
- lambda { }.inspect.should include(project_dir)
267
- lambda { }.inspect.should include('0x')
268
- lambda { }.inspect.should include(' (lambda)') if RUBY_VERSION > '1.9'
269
-
270
- configuration.filter_run :foo => lambda { }
271
- world.inclusion_filter.description.should_not include('0x')
272
- world.inclusion_filter.description.should_not include(project_dir)
273
- world.inclusion_filter.description.should_not include(' (lambda)')
274
- end
275
- end
276
- end
277
-
278
- describe "#exclusion_filter" do
279
- describe "#description" do
280
- it 'returns `{}` when it only contains the default filters' do
281
- world.exclusion_filter.description.should eq({}.inspect)
282
- end
283
-
284
- it 'includes other filters' do
285
- configuration.exclusion_filter[:foo] = :bar
286
- world.exclusion_filter.description.should eq({ :foo => :bar }.inspect)
287
- end
288
-
289
- it 'includes an overriden :if filter' do
290
- configuration.exclusion_filter[:if] = :custom_filter
291
- world.exclusion_filter.description.should eq({ :if => :custom_filter }.inspect)
292
- end
293
-
294
- it 'includes an overriden :unless filter' do
295
- configuration.exclusion_filter[:unless] = :custom_filter
296
- world.exclusion_filter.description.should eq({ :unless => :custom_filter }.inspect)
297
- end
298
-
299
- it 'cleans up the description' do
300
- # check the assumptions of this example
301
- project_dir = File.expand_path('.')
302
- lambda { }.inspect.should include(project_dir)
303
- lambda { }.inspect.should include('0x')
304
- lambda { }.inspect.should include(' (lambda)') if RUBY_VERSION > '1.9'
305
-
306
- configuration.exclusion_filter[:foo] = lambda { }
307
- configuration.filter_run_excluding :bar => lambda { }
308
- world.exclusion_filter.description.should_not include('0x')
309
- world.exclusion_filter.description.should_not include(project_dir)
310
- world.exclusion_filter.description.should_not include(' (lambda)')
311
- end
312
- end
313
- end
314
133
  end
315
134
  end