rspec-core 2.0.0.beta.17 → 2.0.0.beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. data/README.markdown +5 -1
  2. data/Rakefile +4 -1
  3. data/Upgrade.markdown +28 -2
  4. data/VERSION +1 -1
  5. data/autotest/discover.rb +1 -1
  6. data/features/command_line/configure.feature +19 -0
  7. data/features/example_groups/shared_example_group.feature +125 -0
  8. data/features/hooks/around_hooks.feature +11 -2
  9. data/features/pending/pending_examples.feature +18 -6
  10. data/lib/autotest/rspec2.rb +1 -1
  11. data/lib/rspec/core.rb +1 -0
  12. data/lib/rspec/core/command_line_configuration.rb +62 -0
  13. data/lib/rspec/core/configuration.rb +39 -12
  14. data/lib/rspec/core/configuration_options.rb +5 -5
  15. data/lib/rspec/core/deprecation.rb +6 -6
  16. data/lib/rspec/core/errors.rb +1 -1
  17. data/lib/rspec/core/example.rb +25 -25
  18. data/lib/rspec/core/example_group.rb +30 -14
  19. data/lib/rspec/core/formatters/base_formatter.rb +25 -25
  20. data/lib/rspec/core/formatters/base_text_formatter.rb +11 -10
  21. data/lib/rspec/core/formatters/documentation_formatter.rb +2 -2
  22. data/lib/rspec/core/formatters/helpers.rb +6 -6
  23. data/lib/rspec/core/formatters/html_formatter.rb +13 -12
  24. data/lib/rspec/core/formatters/progress_formatter.rb +1 -1
  25. data/lib/rspec/core/formatters/snippet_extractor.rb +5 -5
  26. data/lib/rspec/core/hooks.rb +3 -3
  27. data/lib/rspec/core/kernel_extensions.rb +1 -1
  28. data/lib/rspec/core/let.rb +5 -5
  29. data/lib/rspec/core/metadata.rb +2 -2
  30. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +3 -3
  31. data/lib/rspec/core/mocking/with_mocha.rb +5 -5
  32. data/lib/rspec/core/mocking/with_rr.rb +3 -3
  33. data/lib/rspec/core/mocking/with_rspec.rb +3 -3
  34. data/lib/rspec/core/option_parser.rb +8 -4
  35. data/lib/rspec/core/rake_task.rb +5 -0
  36. data/lib/rspec/core/ruby_project.rb +1 -1
  37. data/lib/rspec/core/shared_example_group.rb +2 -2
  38. data/lib/rspec/core/subject.rb +10 -4
  39. data/lib/rspec/core/world.rb +5 -5
  40. data/rspec-core.gemspec +19 -11
  41. data/spec/autotest/rspec_spec.rb +14 -14
  42. data/spec/rspec/core/command_line_configuration_spec.rb +26 -0
  43. data/spec/rspec/core/command_line_spec.rb +5 -5
  44. data/spec/rspec/core/configuration_options_spec.rb +20 -20
  45. data/spec/rspec/core/configuration_spec.rb +10 -10
  46. data/spec/rspec/core/core_spec.rb +8 -8
  47. data/spec/rspec/core/deprecations_spec.rb +2 -2
  48. data/spec/rspec/core/drb_command_line_spec.rb +10 -10
  49. data/spec/rspec/core/example_group_spec.rb +46 -10
  50. data/spec/rspec/core/example_spec.rb +46 -12
  51. data/spec/rspec/core/formatters/base_formatter_spec.rb +2 -46
  52. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +4 -3
  53. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +1 -1
  54. data/spec/rspec/core/formatters/helpers_spec.rb +2 -2
  55. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +1 -1
  56. data/spec/rspec/core/formatters/html_formatted-1.9.1.html +1 -1
  57. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +1 -1
  58. data/spec/rspec/core/formatters/progress_formatter_spec.rb +10 -9
  59. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +13 -13
  60. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +1 -1
  61. data/spec/rspec/core/let_spec.rb +1 -1
  62. data/spec/rspec/core/metadata_spec.rb +9 -9
  63. data/spec/rspec/core/option_parser_spec.rb +3 -3
  64. data/spec/rspec/core/pending_example_spec.rb +1 -1
  65. data/spec/rspec/core/resources/custom_example_group_runner.rb +1 -1
  66. data/spec/rspec/core/runner_spec.rb +4 -4
  67. data/spec/rspec/core/shared_example_group_spec.rb +66 -162
  68. data/spec/rspec/core/subject_spec.rb +4 -4
  69. data/spec/rspec/core/world_spec.rb +38 -38
  70. metadata +21 -13
@@ -3,29 +3,29 @@ require 'spec_helper'
3
3
  describe RSpec::Core do
4
4
 
5
5
  describe "#configuration" do
6
-
6
+
7
7
  it "returns the same object every time" do
8
8
  RSpec.configuration.should equal(RSpec.configuration)
9
9
  end
10
10
 
11
11
  end
12
-
12
+
13
13
  describe "#configure" do
14
-
14
+
15
15
  it "yields the current configuration" do
16
16
  RSpec.configure do |config|
17
17
  config.should == RSpec::configuration
18
18
  end
19
19
  end
20
-
20
+
21
21
  end
22
-
22
+
23
23
  describe "#world" do
24
-
24
+
25
25
  it "returns the RSpec::Core::World instance the current run is using" do
26
26
  RSpec.world.should be_instance_of(RSpec::Core::World)
27
27
  end
28
-
28
+
29
29
  end
30
-
30
+
31
31
  end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe "deprecations" do
4
4
  describe "Spec" do
5
5
  it "is deprecated" do
6
- RSpec.should_receive(:warn_deprecation).with /Spec .* RSpec/i
6
+ RSpec.should_receive(:warn_deprecation).with(/Spec .* RSpec/i)
7
7
  Spec
8
8
  end
9
9
 
@@ -16,7 +16,7 @@ describe "deprecations" do
16
16
  describe RSpec::Core::ExampleGroup do
17
17
  describe 'running_example' do
18
18
  it 'is deprecated' do
19
- RSpec.should_receive(:warn_deprecation).with /running_example.*example/m
19
+ RSpec.should_receive(:warn_deprecation).with(/running_example.*example/m)
20
20
  self.running_example
21
21
  end
22
22
 
@@ -26,13 +26,13 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
26
26
  err.rewind
27
27
  err.read.should =~ /No DRb server is running/
28
28
  end
29
-
29
+
30
30
  it "returns false" do
31
31
  result = run_with []
32
32
  result.should be_false
33
33
  end
34
34
  end
35
-
35
+
36
36
  describe "--drb-port" do
37
37
  def with_RSPEC_DRB_set_to(val)
38
38
  original = ENV['RSPEC_DRB']
@@ -50,7 +50,7 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
50
50
  drb_command_line([]).drb_port.should == 8989
51
51
  end
52
52
  end
53
-
53
+
54
54
  it "sets the DRb port" do
55
55
  with_RSPEC_DRB_set_to(nil) do
56
56
  drb_command_line(["--drb-port", "1234"]).drb_port.should == 1234
@@ -68,7 +68,7 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
68
68
  end
69
69
  end
70
70
  end
71
-
71
+
72
72
  context "and config variable set" do
73
73
  it "uses configured value" do
74
74
  with_RSPEC_DRB_set_to('9000') do
@@ -81,7 +81,7 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
81
81
 
82
82
  context "with server running" do
83
83
  class ::FakeDrbSpecServer
84
- def self.run(argv, err, out)
84
+ def self.run(argv, err, out)
85
85
  options = RSpec::Core::ConfigurationOptions.new(argv)
86
86
  options.parse_options
87
87
  RSpec::Core::CommandLine.new(options, RSpec::Core::Configuration.new).run(err, out)
@@ -91,7 +91,7 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
91
91
  def dummy_spec_filename
92
92
  @dummy_spec_filename ||= File.expand_path(File.dirname(__FILE__)) + "/_dummy_spec#{@drb_example_file_counter}.rb"
93
93
  end
94
-
94
+
95
95
  before(:all) do
96
96
  @drb_port = 8990
97
97
  @drb_example_file_counter = 0
@@ -132,7 +132,7 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
132
132
  result = drb_command_line(["--drb-port", @drb_port.to_s]).run(err, out)
133
133
  result.should be_true
134
134
  end
135
-
135
+
136
136
  it "integrates via Runner.new.run" do
137
137
  err, out = StringIO.new, StringIO.new
138
138
  result = RSpec::Core::Runner.run(%W[ --drb --drb-port #{@drb_port} #{dummy_spec_filename}], err, out)
@@ -144,16 +144,16 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
144
144
  out.rewind
145
145
  out.read
146
146
  end
147
-
147
+
148
148
  it "should output green colorized text when running with --colour option" do
149
149
  pending "figure out a way to properly sandbox this"
150
150
  run_spec_via_druby.should =~ /\e\[32m/m
151
151
  end
152
-
152
+
153
153
  it "should output red colorized text when running with -c option" do
154
154
  pending "figure out a way to properly sandbox this"
155
155
  run_spec_via_druby.should =~ /\e\[31m/m
156
156
  end
157
157
  end
158
-
158
+
159
159
  end
@@ -254,23 +254,47 @@ module RSpec::Core
254
254
  order.should == [3,2,1]
255
255
  end
256
256
 
257
- it "runs before all, before each, example, after each, after all, in that order" do
258
- group = ExampleGroup.describe
257
+ it "runs before_all_defined_in_config, before all, before each, example, after each, after all, after_all_defined_in_config in that order" do
259
258
  order = []
260
- group.after(:all) { order << :after_all }
261
- group.after(:each) { order << :after_each }
259
+
260
+ RSpec.configure do |c|
261
+ c.before(:all) { order << :before_all_defined_in_config }
262
+ c.after(:all) { order << :after_all_defined_in_config }
263
+ end
264
+
265
+ group = ExampleGroup.describe
266
+ group.before(:all) { order << :top_level_before_all }
262
267
  group.before(:each) { order << :before_each }
263
- group.before(:all) { order << :before_all }
264
- group.example("example") { order << :example }
268
+ group.after(:each) { order << :after_each }
269
+ group.after(:all) { order << :top_level_after_all }
270
+ group.example("top level example") { order << :top_level_example }
271
+
272
+ context1 = group.describe("context 1")
273
+ context1.before(:all) { order << :nested_before_all }
274
+ context1.example("nested example 1") { order << :nested_example_1 }
275
+
276
+ context2 = group.describe("context 2")
277
+ context2.after(:all) { order << :nested_after_all }
278
+ context2.example("nested example 2") { order << :nested_example_2 }
265
279
 
266
280
  group.run_all
267
281
 
268
282
  order.should == [
269
- :before_all,
283
+ :before_all_defined_in_config,
284
+ :top_level_before_all,
285
+ :before_each,
286
+ :top_level_example,
287
+ :after_each,
288
+ :nested_before_all,
289
+ :before_each,
290
+ :nested_example_1,
291
+ :after_each,
270
292
  :before_each,
271
- :example,
293
+ :nested_example_2,
272
294
  :after_each,
273
- :after_all
295
+ :nested_after_all,
296
+ :top_level_after_all,
297
+ :after_all_defined_in_config
274
298
  ]
275
299
  end
276
300
 
@@ -376,7 +400,7 @@ module RSpec::Core
376
400
 
377
401
  end
378
402
 
379
- describe Object, "describing nested example_groups", :little_less_nested => 'yep' do
403
+ describe Object, "describing nested example_groups", :little_less_nested => 'yep' do
380
404
 
381
405
  describe "A sample nested group", :nested_describe => "yep" do
382
406
  it "sets the described class to the constant Object" do
@@ -511,6 +535,18 @@ module RSpec::Core
511
535
  end
512
536
  its(:nil_value) { should be_nil }
513
537
  end
538
+
539
+ context "with nested attributes" do
540
+ subject do
541
+ Class.new do
542
+ def name
543
+ "John"
544
+ end
545
+ end.new
546
+ end
547
+ its("name.size") { should == 4 }
548
+ its("name.size.class") { should == Fixnum }
549
+ end
514
550
  end
515
551
 
516
552
  describe "#top_level_description" do
@@ -16,18 +16,6 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
16
16
  end
17
17
  end
18
18
 
19
- describe '#inspect' do
20
- it "should return 'group description - description'" do
21
- example_instance.inspect.should == 'group description example description'
22
- end
23
- end
24
-
25
- describe '#to_s' do
26
- it "should return #inspect" do
27
- example_instance.to_s.should == example_instance.inspect
28
- end
29
- end
30
-
31
19
  describe '#described_class' do
32
20
  it "returns the class (if any) of the outermost example group" do
33
21
  described_class.should == RSpec::Core::Example
@@ -140,4 +128,50 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
140
128
  example.should_not be_in_block
141
129
  end
142
130
  end
131
+
132
+ describe "#pending" do
133
+ context "in the example" do
134
+ it "sets the example to pending" do
135
+ group = RSpec::Core::ExampleGroup.describe do
136
+ example { pending }
137
+ end
138
+ group.run_all
139
+ group.examples.first.should be_pending
140
+ end
141
+ end
142
+
143
+ context "in before(:each)" do
144
+ it "sets the example to pending" do
145
+ group = RSpec::Core::ExampleGroup.describe do
146
+ before(:each) { pending }
147
+ example {}
148
+ end
149
+ group.run_all
150
+ group.examples.first.should be_pending
151
+ end
152
+ end
153
+
154
+ context "in around(:each)" do
155
+ it "sets the example to pending" do
156
+ group = RSpec::Core::ExampleGroup.describe do
157
+ around(:each) { pending }
158
+ example {}
159
+ end
160
+ group.run_all
161
+ group.examples.first.should be_pending
162
+ end
163
+ end
164
+
165
+ context "in before(:all)" do
166
+ it "is not supported" do
167
+ group = RSpec::Core::ExampleGroup.describe do
168
+ before(:all) { pending }
169
+ example {}
170
+ end
171
+ expect do
172
+ group.run_all
173
+ end.to raise_error(/undefined method `metadata'/)
174
+ end
175
+ end
176
+ end
143
177
  end
@@ -1,58 +1,14 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe RSpec::Core::Formatters::BaseFormatter do
4
-
4
+
5
5
  let(:output) { StringIO.new }
6
6
  let(:formatter) { RSpec::Core::Formatters::BaseFormatter.new(output) }
7
7
 
8
- it "has start as an interface with one argument" do
9
- formatter.should have_interface_for(:start).with(1).argument
10
- end
11
-
12
- it "has add_example_group as an interface with one argument" do
13
- formatter.should have_interface_for(:add_example_group).with(1).argument
14
- end
15
-
16
- it "has example_passed as an interface with one argument" do
17
- formatter.should have_interface_for(:example_passed).with(1).arguments
18
- end
19
-
20
- it "has example_pending as an interface with one argument" do
21
- formatter.should have_interface_for(:example_pending).with(1).arguments
22
- end
23
-
24
- it "has example_failed as an interface with one argument" do
25
- formatter.should have_interface_for(:example_failed).with(1).arguments
26
- end
27
-
28
- it "has start_dump as an interface with 1 arguments" do
29
- formatter.should have_interface_for(:start_dump).with(1).arguments
30
- end
31
-
32
- it "has dump_failures as an interface with no arguments" do
33
- formatter.should have_interface_for(:dump_failures).with(0).arguments
34
- end
35
-
36
- it "has dump_summary as an interface with zero arguments" do
37
- formatter.should have_interface_for(:dump_summary).with(0).arguments
38
- end
39
-
40
- it "has dump_pending as an interface with zero arguments" do
41
- formatter.should have_interface_for(:dump_pending).with(0).arguments
42
- end
43
-
44
- it "has close as an interface with zero arguments" do
45
- formatter.should have_interface_for(:close).with(0).arguments
46
- end
47
-
48
- describe '#format_backtrace' do
49
- it "displays the full backtrace when the example is given the :full_backtrace => true option", :full_backtrace => true
50
- end
51
-
52
8
  describe "backtrace_line" do
53
9
  it "trims current working directory" do
54
10
  formatter.__send__(:backtrace_line, File.expand_path(__FILE__)).should == "./spec/rspec/core/formatters/base_formatter_spec.rb"
55
11
  end
56
12
  end
57
-
13
+
58
14
  end
@@ -27,15 +27,16 @@ module RSpec::Core::Formatters
27
27
  end
28
28
 
29
29
  describe "#dump_failures" do
30
- it "preserves formatting" do
30
+ it "preserves formatting" do
31
31
  output = StringIO.new
32
- group = RSpec::Core::ExampleGroup.describe
33
- example = group.example { "this".should eq("that") }
32
+ group = RSpec::Core::ExampleGroup.describe("group name")
33
+ example = group.example("example name") { "this".should eq("that") }
34
34
  formatter = RSpec::Core::Formatters::BaseTextFormatter.new(output)
35
35
  group.run_all(formatter)
36
36
 
37
37
  RSpec.configuration.stub(:color_enabled?) { false }
38
38
  formatter.dump_failures
39
+ output.string.should =~ /group name example name/m
39
40
  output.string.should =~ /(\s+)expected \"that\"\n\1 got \"this\"/m
40
41
  end
41
42
  end
@@ -19,7 +19,7 @@ module RSpec::Core::Formatters
19
19
  RSpec.configuration.stub(:color_enabled?) { false }
20
20
 
21
21
  formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output)
22
-
22
+
23
23
  examples.each {|e| formatter.example_failed(e) }
24
24
 
25
25
  output.string.should =~ /first example \(FAILED - 1\)/m
@@ -39,8 +39,8 @@ describe RSpec::Core::Formatters::Helpers do
39
39
  helper.format_seconds(5.0).should == "5"
40
40
  end
41
41
 
42
- end
42
+ end
43
43
  end
44
44
 
45
-
45
+
46
46
  end
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE html
2
+ <!DOCTYPE html
3
3
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
4
4
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5
5
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE html
2
+ <!DOCTYPE html
3
3
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
4
4
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5
5
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE html
2
+ <!DOCTYPE html
3
3
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
4
4
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5
5
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
@@ -2,28 +2,29 @@ require 'spec_helper'
2
2
  require 'stringio'
3
3
 
4
4
  describe RSpec::Core::Formatters::ProgressFormatter do
5
-
5
+
6
6
  before do
7
7
  @output = StringIO.new
8
8
  @formatter = RSpec::Core::Formatters::ProgressFormatter.new(@output)
9
9
  @formatter.start(2)
10
10
  @formatter.stub!(:color_enabled?).and_return(false)
11
11
  end
12
-
12
+
13
13
  it "should produce line break on start dump" do
14
- @formatter.start_dump(3)
14
+ @formatter.start_dump
15
15
  @output.string.should == "\n"
16
16
  end
17
-
17
+
18
18
  it "should produce standard summary without pending when pending has a 0 count" do
19
- @formatter.start_dump(3)
20
- @formatter.dump_summary
21
- @output.string.should =~ /Finished in 3 seconds\n2 examples/i
19
+ @formatter.start_dump
20
+ @formatter.dump_summary(0.00001, 2, 0, 0)
21
+ @output.string.should =~ /2 examples, 0 failures/i
22
+ @output.string.should_not =~ /0 pending/i
22
23
  end
23
-
24
+
24
25
  it "should push nothing on start" do
25
26
  @formatter.start(4)
26
27
  @output.string.should == ""
27
28
  end
28
-
29
+
29
30
  end