rspec 1.1.8 → 1.1.9

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 (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
@@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  module Spec
4
4
  module Extensions
5
5
  describe Main do
6
- include SandboxedOptions
7
6
  before(:each) do
8
7
  @main = Class.new do; include Main; end
9
8
  end
@@ -11,41 +10,42 @@ module Spec
11
10
  after(:each) do
12
11
  $rspec_story_steps = @original_rspec_story_steps
13
12
  end
13
+
14
+ [:describe, :context].each do |method|
15
+ describe "##{method}" do
16
+ specify {@main.should respond_to(method)}
14
17
 
15
- specify {@main.should respond_to(:describe)}
16
- specify {@main.should respond_to(:context)}
18
+ it "should raise when no block is given to #{method}" do
19
+ lambda { @main.__send__ method, "foo" }.should raise_error(ArgumentError)
20
+ end
17
21
 
18
- it "should raise when no block given to describe" do
19
- lambda { @main.describe "foo" }.should raise_error(ArgumentError)
20
- end
22
+ it "should raise when no description is given to #{method}" do
23
+ lambda { @main.__send__ method do; end }.should raise_error(ArgumentError)
24
+ end
21
25
 
22
- it "should raise when no description given to describe" do
23
- lambda { @main.describe do; end }.should raise_error(ArgumentError)
24
- end
25
-
26
- it "should registered ExampleGroups by default" do
27
- example_group = @main.describe("The ExampleGroup") do end
28
- Spec::Runner.options.example_groups.should include(example_group)
29
- end
26
+ it "should run registered ExampleGroups" do
27
+ example_group = @main.__send__ method, "The ExampleGroup" do end
28
+ Spec::Runner.options.example_groups.should include(example_group)
29
+ end
30
30
 
31
- it "should not run unregistered ExampleGroups" do
32
- example_group = @main.describe("The ExampleGroup") do
33
- unregister
31
+ it "should not run unregistered ExampleGroups" do
32
+ example_group = @main.__send__ method, "The ExampleGroup" do unregister; end
33
+ Spec::Runner.options.example_groups.should_not include(example_group)
34
+ end
34
35
  end
35
-
36
- Spec::Runner.options.example_groups.should_not include(example_group)
37
36
  end
38
37
 
39
- it "should create a shared ExampleGroup with share_examples_for" do
40
- group = @main.share_examples_for "all things" do end
41
- group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
38
+ describe "#share_examples_for" do
39
+ it "should create a shared ExampleGroup" do
40
+ group = @main.share_examples_for "all things" do end
41
+ group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
42
+ end
42
43
  end
43
44
 
44
45
  describe "#share_as" do
45
46
  before(:each) do
46
47
  $share_as_examples_example_module_number ||= 1
47
48
  $share_as_examples_example_module_number += 1
48
- t = Time.new.to_i
49
49
  @group_name = "Group#{$share_as_examples_example_module_number}"
50
50
  end
51
51
 
@@ -0,0 +1,13 @@
1
+ rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
2
+ $:.unshift rspec_lib unless $:.include?(rspec_lib)
3
+ require 'test/unit'
4
+ require 'spec'
5
+
6
+ describe "options hash" do
7
+ describe "#options" do
8
+ it "should expose the options hash" do
9
+ group = describe("group", :this => 'hash') {}
10
+ group.options[:this].should == 'hash'
11
+ end
12
+ end
13
+ end
@@ -3,43 +3,50 @@ require File.dirname(__FILE__) + '/test_unit_spec_helper'
3
3
  describe "ExampleGroup with test/unit/interop" do
4
4
  include TestUnitSpecHelper
5
5
 
6
- before(:each) do
7
- @dir = File.dirname(__FILE__) + "/resources"
6
+ def resources
7
+ File.dirname(__FILE__) + "/resources"
8
8
  end
9
9
 
10
10
  describe "with passing examples" do
11
11
  it "should output 0 failures" do
12
- output = ruby("#{@dir}/spec_that_passes.rb")
12
+ output = ruby("#{resources}/spec_that_passes.rb")
13
13
  output.should include("1 example, 0 failures")
14
14
  end
15
15
 
16
16
  it "should return an exit code of 0" do
17
- ruby("#{@dir}/spec_that_passes.rb")
17
+ ruby("#{resources}/spec_that_passes.rb")
18
18
  $?.should == 0
19
19
  end
20
20
  end
21
21
 
22
22
  describe "with failing examples" do
23
23
  it "should output 1 failure" do
24
- output = ruby("#{@dir}/spec_that_fails.rb")
24
+ output = ruby("#{resources}/spec_that_fails.rb")
25
25
  output.should include("1 example, 1 failure")
26
26
  end
27
27
 
28
28
  it "should return an exit code of 256" do
29
- ruby("#{@dir}/spec_that_fails.rb")
29
+ ruby("#{resources}/spec_that_fails.rb")
30
30
  $?.should == 256
31
31
  end
32
32
  end
33
33
 
34
34
  describe "with example that raises an error" do
35
35
  it "should output 1 failure" do
36
- output = ruby("#{@dir}/spec_with_errors.rb")
36
+ output = ruby("#{resources}/spec_with_errors.rb")
37
37
  output.should include("1 example, 1 failure")
38
38
  end
39
39
 
40
40
  it "should return an exit code of 256" do
41
- ruby("#{@dir}/spec_with_errors.rb")
41
+ ruby("#{resources}/spec_with_errors.rb")
42
42
  $?.should == 256
43
43
  end
44
44
  end
45
+
46
+ describe "options hash" do
47
+ it "should be exposed" do
48
+ output = ruby("#{resources}/spec_with_options_hash.rb")
49
+ output.should include("1 example, 0 failures")
50
+ end
51
+ end
45
52
  end
@@ -451,11 +451,21 @@ module Spec
451
451
  it "should not mess with the stub's yielded values when also mocked" do
452
452
  @mock.stub!(:yield_back).and_yield(:stub_value)
453
453
  @mock.should_receive(:yield_back).and_yield(:mock_value)
454
- @mock.yield_back{|v| v}.should == :mock_value
455
- @mock.yield_back{|v| v}.should == :stub_value
454
+ @mock.yield_back{|v| v.should == :mock_value }
455
+ @mock.yield_back{|v| v.should == :stub_value }
456
456
  @mock.rspec_verify
457
457
  end
458
458
 
459
+ it "should yield multiple values after a similar stub" do
460
+ File.stub!(:open).and_yield(:stub_value)
461
+ File.should_receive(:open).and_yield(:first_call).and_yield(:second_call)
462
+ yielded_args = []
463
+ File.open {|v| yielded_args << v }
464
+ yielded_args.should == [:first_call, :second_call]
465
+ File.open {|v| v.should == :stub_value }
466
+ File.rspec_verify
467
+ end
468
+
459
469
  it "should assign stub return values" do
460
470
  mock = Mock.new('name', :message => :response)
461
471
  mock.message.should == :response
@@ -31,7 +31,6 @@ module Spec
31
31
  end
32
32
 
33
33
  describe "#allow_message_expectations_on_nil" do
34
- include SandboxedOptions
35
34
 
36
35
  it "should not effect subsequent examples" do
37
36
  example_group = Class.new(ExampleGroup)
@@ -11,7 +11,14 @@ module Spec
11
11
  @object.should_receive(:foo)
12
12
  lambda do
13
13
  @object.rspec_verify
14
- end.should raise_error(Spec::Mocks::MockExpectationError, /Object/)
14
+ end.should raise_error(Spec::Mocks::MockExpectationError, /<Object:.*> expected/)
15
+ end
16
+
17
+ it "should name the class in the failure message when expectation is on class" do
18
+ Object.should_receive(:foo)
19
+ lambda do
20
+ Object.rspec_verify
21
+ end.should raise_error(Spec::Mocks::MockExpectationError, /<Object \(class\)>/)
15
22
  end
16
23
 
17
24
  it "should not conflict with @options in the object" do
@@ -21,11 +28,10 @@ module Spec
21
28
  end
22
29
 
23
30
  it "should_not_receive should mock out the method" do
24
- pending("example raises the expected error, yet fails")
25
31
  @object.should_not_receive(:fuhbar)
26
32
  lambda do
27
33
  @object.fuhbar
28
- end.should raise_error(MockExpectationError, "Mock 'Object' expected :fuhbar with (no args) 0 times, but received it once")
34
+ end.should raise_error(MockExpectationError, /<Object:.*> expected :fuhbar with \(no args\) 0 times/)
29
35
  end
30
36
 
31
37
  it "should_not_receive should return a negative message expectation" do
@@ -66,7 +72,6 @@ module Spec
66
72
  end
67
73
 
68
74
  it "should_not_receive should also take a String argument" do
69
- pending("example raises the expected error, yet fails")
70
75
  @object.should_not_receive('foobar')
71
76
  lambda do
72
77
  @object.foobar
@@ -79,7 +84,7 @@ module Spec
79
84
  @this_will_resolve_to_nil.should_receive(:foobar)
80
85
  lambda do
81
86
  @this_will_resolve_to_nil.rspec_verify
82
- end.should raise_error(Spec::Mocks::MockExpectationError, /NilClass.*expected :foobar with/)
87
+ end.should raise_error(Spec::Mocks::MockExpectationError, /nil expected :foobar with/)
83
88
  end
84
89
  end
85
90
 
@@ -11,4 +11,12 @@ describe "The bin/spec script" do
11
11
  output = ruby "-w #{spec_path} --help 2>&1"
12
12
  output.should_not =~ /warning/n
13
13
  end
14
+
15
+ it "should show the help w/ no args" do
16
+ pending "Hangs on JRuby" if PLATFORM =~ /java/
17
+ spec_path = "#{File.dirname(__FILE__)}/../../../bin/spec"
18
+
19
+ output = ruby "-w #{spec_path} 2>&1"
20
+ output.should =~ /^Usage: spec/
21
+ end
14
22
  end
@@ -3,137 +3,138 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  module Spec
4
4
  module Runner
5
5
  describe CommandLine, ".run" do
6
- include SandboxedOptions
7
- attr_reader :options, :err, :out
8
- before do
9
- @err = options.error_stream
10
- @out = options.output_stream
11
- end
6
+ with_sandboxed_options do
7
+ attr_reader :err, :out
8
+ before do
9
+ @err = options.error_stream
10
+ @out = options.output_stream
11
+ end
12
12
 
13
- it "should run directory" do
14
- file = File.dirname(__FILE__) + '/../../../examples/pure'
15
- run_with(OptionParser.parse([file,"-p","**/*.rb"], @err, @out))
13
+ it "should run directory" do
14
+ file = File.dirname(__FILE__) + '/../../../examples/pure'
15
+ run_with(OptionParser.parse([file,"-p","**/*.rb"], @err, @out))
16
16
 
17
- @out.rewind
18
- @out.read.should =~ /\d+ examples, 0 failures, 3 pending/n
19
- end
17
+ @out.rewind
18
+ @out.read.should =~ /\d+ examples, 0 failures, 3 pending/n
19
+ end
20
20
 
21
- it "should run file" do
22
- file = File.dirname(__FILE__) + '/../../../failing_examples/predicate_example.rb'
23
- run_with(OptionParser.parse([file], @err, @out))
21
+ it "should run file" do
22
+ file = File.dirname(__FILE__) + '/../../../failing_examples/predicate_example.rb'
23
+ run_with(OptionParser.parse([file], @err, @out))
24
24
 
25
- @out.rewind
26
- @out.read.should =~ /2 examples, 1 failure/n
27
- end
25
+ @out.rewind
26
+ @out.read.should =~ /2 examples, 1 failure/n
27
+ end
28
28
 
29
- it "should raise when file does not exist" do
30
- file = File.dirname(__FILE__) + '/doesntexist'
29
+ it "should raise when file does not exist" do
30
+ file = File.dirname(__FILE__) + '/doesntexist'
31
31
 
32
- lambda {
33
- Spec::Runner::CommandLine.run(OptionParser.parse([file], @err, @out))
34
- }.should raise_error
35
- end
32
+ lambda {
33
+ Spec::Runner::CommandLine.run(OptionParser.parse([file], @err, @out))
34
+ }.should raise_error
35
+ end
36
36
 
37
- it "should return true when in --generate-options mode" do
38
- # NOTE - this used to say /dev/null but jruby hangs on that for some reason
39
- Spec::Runner::CommandLine.run(
40
- OptionParser.parse(['--generate-options', '/tmp/foo'], @err, @out)
41
- ).should be_true
42
- end
37
+ it "should return true when in --generate-options mode" do
38
+ # NOTE - this used to say /dev/null but jruby hangs on that for some reason
39
+ Spec::Runner::CommandLine.run(
40
+ OptionParser.parse(['--generate-options', '/tmp/foo'], @err, @out)
41
+ ).should be_true
42
+ end
43
43
 
44
- it "should dump even if Interrupt exception is occurred" do
45
- example_group = Class.new(::Spec::Example::ExampleGroup) do
46
- describe("example_group")
47
- it "no error" do
48
- end
44
+ it "should dump even if Interrupt exception is occurred" do
45
+ example_group = Class.new(::Spec::Example::ExampleGroup) do
46
+ describe("example_group")
47
+ it "no error" do
48
+ end
49
49
 
50
- it "should interrupt" do
51
- raise Interrupt, "I'm interrupting"
50
+ it "should interrupt" do
51
+ raise Interrupt, "I'm interrupting"
52
+ end
52
53
  end
53
- end
54
54
 
55
- options = ::Spec::Runner::Options.new(@err, @out)
56
- ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
57
- options.reporter.should_receive(:dump)
58
- options.add_example_group(example_group)
55
+ options = ::Spec::Runner::Options.new(@err, @out)
56
+ ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
57
+ options.reporter.should_receive(:dump)
58
+ options.add_example_group(example_group)
59
59
 
60
- Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
61
- end
60
+ Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
61
+ end
62
62
 
63
- it "should heckle when options have heckle_runner" do
64
- example_group = Class.new(::Spec::Example::ExampleGroup).describe("example_group") do
65
- it "no error" do
63
+ it "should heckle when options have heckle_runner" do
64
+ example_group = Class.new(::Spec::Example::ExampleGroup).describe("example_group") do
65
+ it "no error" do
66
+ end
66
67
  end
67
- end
68
- options = ::Spec::Runner::Options.new(@err, @out)
69
- ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
70
- options.add_example_group example_group
68
+ options = ::Spec::Runner::Options.new(@err, @out)
69
+ ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
70
+ options.add_example_group example_group
71
71
 
72
- heckle_runner = mock("heckle_runner")
73
- heckle_runner.should_receive(:heckle_with)
74
- $rspec_mocks.__send__(:mocks).delete(heckle_runner)
72
+ heckle_runner = mock("heckle_runner")
73
+ heckle_runner.should_receive(:heckle_with)
74
+ $rspec_mocks.__send__(:mocks).delete(heckle_runner)
75
75
 
76
- options.heckle_runner = heckle_runner
77
- options.add_example_group(example_group)
76
+ options.heckle_runner = heckle_runner
77
+ options.add_example_group(example_group)
78
78
 
79
- Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
80
- heckle_runner.rspec_verify
81
- end
79
+ Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
80
+ heckle_runner.rspec_verify
81
+ end
82
82
 
83
- it "should run examples backwards if options.reverse is true" do
84
- options = ::Spec::Runner::Options.new(@err, @out)
85
- ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
86
- options.reverse = true
83
+ it "should run examples backwards if options.reverse is true" do
84
+ options = ::Spec::Runner::Options.new(@err, @out)
85
+ ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
86
+ options.reverse = true
87
87
 
88
- b1 = Class.new(Spec::Example::ExampleGroup)
89
- b2 = Class.new(Spec::Example::ExampleGroup)
88
+ b1 = Class.new(Spec::Example::ExampleGroup)
89
+ b2 = Class.new(Spec::Example::ExampleGroup)
90
90
 
91
- b2.should_receive(:run).ordered
92
- b1.should_receive(:run).ordered
91
+ b2.should_receive(:run).ordered
92
+ b1.should_receive(:run).ordered
93
93
 
94
- options.add_example_group(b1)
95
- options.add_example_group(b2)
94
+ options.add_example_group(b1)
95
+ options.add_example_group(b2)
96
96
 
97
- Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
98
- end
97
+ Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
98
+ end
99
99
 
100
- it "should pass its ExampleGroup to the reporter" do
101
- example_group = Class.new(::Spec::Example::ExampleGroup).describe("example_group") do
102
- it "should" do
100
+ it "should pass its ExampleGroup to the reporter" do
101
+ example_group = describe("example_group") do
102
+ it "should" do
103
+ end
103
104
  end
104
- end
105
- options = ::Spec::Runner::Options.new(@err, @out)
106
- options.add_example_group(example_group)
105
+ options = ::Spec::Runner::Options.new(@err, @out)
106
+ options.add_example_group(example_group)
107
107
 
108
- ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
109
- options.reporter.should_receive(:add_example_group).with(example_group)
108
+ ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
109
+ options.reporter.should_receive(:add_example_group).with(example_group)
110
110
 
111
- Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
112
- end
113
-
114
- it "runs only selected Examples when options.examples is set" do
115
- options = ::Spec::Runner::Options.new(@err, @out)
116
- ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
111
+ Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
112
+ end
117
113
 
118
- options.examples << "example_group should"
119
- should_has_run = false
120
- should_not_has_run = false
121
- example_group = Class.new(::Spec::Example::ExampleGroup).describe("example_group") do
122
- it "should" do
123
- should_has_run = true
114
+ it "runs only selected Examples when options.examples is set" do
115
+ options = ::Spec::Runner::Options.new(@err, @out)
116
+ ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
117
+
118
+ options.examples << "example group expected example"
119
+ expected_example_was_run = false
120
+ unexpected_example_was_run = false
121
+ example_group = describe("example group") do
122
+ it "expected example" do
123
+ expected_example_was_run = true
124
+ end
125
+ it "unexpected example" do
126
+ unexpected_example_was_run = true
127
+ end
124
128
  end
125
- it "should not" do
126
- should_not_has_run = true
127
- end
128
- end
129
129
 
130
- options.reporter.should_receive(:add_example_group).with(example_group)
130
+ options.reporter.should_receive(:add_example_group).with(example_group)
131
131
 
132
- options.add_example_group example_group
133
- run_with(options)
132
+ options.add_example_group example_group
133
+ run_with(options)
134
134
 
135
- should_has_run.should be_true
136
- should_not_has_run.should be_false
135
+ expected_example_was_run.should be_true
136
+ unexpected_example_was_run.should be_false
137
+ end
137
138
  end
138
139
  end
139
140
  end