rspec 0.9.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/CHANGES +24 -0
  2. data/EXAMPLES.rd +6 -2
  3. data/README +9 -9
  4. data/Rakefile +32 -29
  5. data/examples/not_yet_implemented_spec.rb +12 -0
  6. data/examples/shared_behaviours_example.rb +8 -0
  7. data/examples/stack_spec.rb +1 -0
  8. data/lib/spec/dsl/behaviour.rb +21 -6
  9. data/lib/spec/dsl/behaviour_callbacks.rb +44 -26
  10. data/lib/spec/dsl/behaviour_eval.rb +21 -12
  11. data/lib/spec/dsl/behaviour_factory.rb +23 -13
  12. data/lib/spec/dsl/configuration.rb +85 -5
  13. data/lib/spec/dsl/description.rb +14 -6
  14. data/lib/spec/dsl/example.rb +2 -2
  15. data/lib/spec/matchers.rb +5 -5
  16. data/lib/spec/matchers/be.rb +16 -0
  17. data/lib/spec/matchers/operator_matcher.rb +21 -1
  18. data/lib/spec/matchers/raise_error.rb +1 -1
  19. data/lib/spec/rake/verify_rcov.rb +5 -1
  20. data/lib/spec/runner.rb +7 -27
  21. data/lib/spec/runner/behaviour_runner.rb +1 -1
  22. data/lib/spec/runner/extensions/kernel.rb +20 -0
  23. data/lib/spec/runner/formatter/base_formatter.rb +6 -1
  24. data/lib/spec/runner/formatter/base_text_formatter.rb +10 -2
  25. data/lib/spec/runner/formatter/failing_behaviours_formatter.rb +1 -1
  26. data/lib/spec/runner/formatter/failing_examples_formatter.rb +1 -1
  27. data/lib/spec/runner/formatter/html_formatter.rb +63 -31
  28. data/lib/spec/runner/formatter/progress_bar_formatter.rb +5 -0
  29. data/lib/spec/runner/formatter/rdoc_formatter.rb +4 -0
  30. data/lib/spec/runner/formatter/specdoc_formatter.rb +6 -1
  31. data/lib/spec/runner/option_parser.rb +1 -1
  32. data/lib/spec/runner/reporter.rb +13 -4
  33. data/lib/spec/runner/spec_parser.rb +1 -1
  34. data/lib/spec/version.rb +5 -5
  35. data/spec/spec/dsl/behaviour_spec.rb +88 -24
  36. data/spec/spec/dsl/configuration_spec.rb +8 -1
  37. data/spec/spec/dsl/example_class_spec.rb +1 -1
  38. data/spec/spec/dsl/example_instance_spec.rb +5 -5
  39. data/spec/spec/dsl/shared_behaviour_spec.rb +24 -2
  40. data/spec/spec/matchers/be_spec.rb +20 -2
  41. data/spec/spec/matchers/operator_matcher_spec.rb +158 -0
  42. data/spec/spec/runner/command_line_spec.rb +5 -4
  43. data/spec/spec/runner/drb_command_line_spec.rb +15 -8
  44. data/spec/spec/runner/formatter/html_formatter_spec.rb +22 -5
  45. data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +1 -1
  46. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +7 -2
  47. data/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb +1 -1
  48. data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +6 -1
  49. data/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb +1 -1
  50. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +15 -5
  51. data/spec/spec/runner/option_parser_spec.rb +5 -0
  52. data/spec/spec/runner/reporter_spec.rb +23 -5
  53. data/spec/spec/runner/spec_matcher_spec.rb +1 -1
  54. data/spec/spec/runner/spec_parser_spec.rb +1 -1
  55. data/spec/spec_helper.rb +38 -2
  56. metadata +41 -42
  57. data/spec/spec/matchers/should_===_spec.rb +0 -38
  58. data/spec/spec/matchers/should_==_spec.rb +0 -37
  59. data/spec/spec/matchers/should_=~_spec.rb +0 -36
@@ -12,7 +12,7 @@ module Spec
12
12
  @config.mock_framework.should =~ /\/plugins\/mock_frameworks\/rspec$/
13
13
  end
14
14
 
15
- it "should let you set rspec explicitly" do
15
+ it "should let you set rspec mocking explicitly" do
16
16
  @config.mock_with(:rspec)
17
17
  @config.mock_framework.should =~ /\/plugins\/mock_frameworks\/rspec$/
18
18
  end
@@ -38,6 +38,13 @@ module Spec
38
38
  @config.include mod
39
39
  @config.included_modules.should include(mod)
40
40
  end
41
+
42
+ [:prepend_before, :append_before, :prepend_after, :append_after].each do |m|
43
+ it "should delegate ##{m} to Behaviour class" do
44
+ Behaviour.should_receive(m).with(:whatever)
45
+ @config.__send__(m, :whatever)
46
+ end
47
+ end
41
48
  end
42
49
  end
43
50
  end
@@ -15,7 +15,7 @@ module Spec
15
15
 
16
16
  it "should report errors in example" do
17
17
  error = Exception.new
18
- @reporter.should_receive(:example_finished).with("example", error, "example")
18
+ @reporter.should_receive(:example_finished).with("example", error, "example", false)
19
19
 
20
20
  run(@example_class.new("example") {raise(error)})
21
21
  end
@@ -27,7 +27,7 @@ module Spec
27
27
 
28
28
  it "should report success" do
29
29
  example=Example.new("example") {}
30
- @reporter.should_receive(:example_finished).with("example", nil, nil)
30
+ @reporter.should_receive(:example_finished).with("example", nil, nil, false)
31
31
  example.run(@reporter, nil, nil, nil, nil)
32
32
  end
33
33
 
@@ -35,7 +35,7 @@ module Spec
35
35
  example=Example.new("example") do
36
36
  (2+2).should == 5
37
37
  end
38
- @reporter.should_receive(:example_finished).with("example", is_a(Spec::Expectations::ExpectationNotMetError), "example")
38
+ @reporter.should_receive(:example_finished).with("example", is_a(Spec::Expectations::ExpectationNotMetError), "example", false)
39
39
  example.run(@reporter, nil, nil, nil, nil)
40
40
  end
41
41
 
@@ -44,7 +44,7 @@ module Spec
44
44
  example=Example.new("example") do
45
45
  raise(error)
46
46
  end
47
- @reporter.should_receive(:example_finished).with("example", error, "example")
47
+ @reporter.should_receive(:example_finished).with("example", error, "example", false)
48
48
  example.run(@reporter, nil, nil, nil, nil)
49
49
  end
50
50
 
@@ -54,7 +54,7 @@ module Spec
54
54
  self.instance_of?(Example).should == false
55
55
  self.instance_of?(scope_class).should == true
56
56
  end
57
- @reporter.should_receive(:example_finished).with("should pass", nil, nil)
57
+ @reporter.should_receive(:example_finished).with("should pass", nil, nil, false)
58
58
  example.run(@reporter, nil, nil, nil, scope_class.new)
59
59
  end
60
60
 
@@ -148,7 +148,7 @@ module Spec
148
148
  example = Example.new(:__generate_description) {
149
149
  5.should == 5
150
150
  }
151
- @reporter.should_receive(:example_finished).with("should == 5", :anything, :anything)
151
+ @reporter.should_receive(:example_finished).with("should == 5", :anything, :anything, false)
152
152
  example.run(@reporter, nil, nil, nil, Object.new)
153
153
  end
154
154
 
@@ -6,7 +6,7 @@ module Spec
6
6
 
7
7
  before do
8
8
  @formatter = Spec::Mocks::Mock.new("formatter", :null_object => true)
9
- @behaviour = behaviour_class.new("context") {}
9
+ @behaviour = behaviour_class.new("behaviour") {}
10
10
  end
11
11
 
12
12
  after do
@@ -66,11 +66,17 @@ module Spec
66
66
  shared_behaviour.number_of_examples.should == 1
67
67
  end
68
68
 
69
- it "should complain when adding a shared behaviour with the same description" do
69
+ it "should complain when adding a second shared behaviour with the same description" do
70
70
  make_shared_behaviour("shared behaviour", :shared => true) {}
71
71
  lambda { make_shared_behaviour("shared behaviour", :shared => true) {} }.should raise_error(ArgumentError)
72
72
  end
73
73
 
74
+ it "should NOT complain when adding a the same shared behaviour again (i.e. file gets reloaded)" do
75
+ behaviour = behaviour_class.new("shared behaviour", :shared => true) {}
76
+ behaviour_class.add_shared_behaviour(behaviour)
77
+ behaviour_class.add_shared_behaviour(behaviour)
78
+ end
79
+
74
80
  it "should add examples to current behaviour when calling it_should_behave_like" do
75
81
  shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
76
82
  shared_behaviour.it("shared example") {}
@@ -166,6 +172,22 @@ module Spec
166
172
  mod1_method_called.should be_true
167
173
  mod2_method_called.should be_true
168
174
  end
175
+
176
+ it "should make methods defined in the shared behaviour available in consuming behaviour" do
177
+ shared_behaviour = make_shared_behaviour("shared behaviour xyz", :shared => true) do
178
+ def a_shared_helper_method
179
+ "this got defined in a shared behaviour"
180
+ end
181
+ end
182
+ @behaviour.it_should_behave_like("shared behaviour xyz")
183
+ success = false
184
+ @behaviour.it("should access a_shared_helper_method") do
185
+ a_shared_helper_method
186
+ success = true
187
+ end
188
+ @behaviour.run(@formatter)
189
+ success.should be_true
190
+ end
169
191
 
170
192
  it "should error if told to inherit from a class" do
171
193
  shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
@@ -179,6 +179,26 @@ describe "should be >" do
179
179
  end
180
180
  end
181
181
 
182
+ describe "should be ==" do
183
+ it "should pass when == operator returns true" do
184
+ 5.should be == 5
185
+ end
186
+
187
+ it "should fail when == operator returns false" do
188
+ lambda { 3.should be == 4 }.should fail_with("expected == 4, got 3")
189
+ end
190
+ end
191
+
192
+ describe "should be ===" do
193
+ it "should pass when === operator returns true" do
194
+ Hash.should be === Hash.new
195
+ end
196
+
197
+ it "should fail when === operator returns false" do
198
+ lambda { Hash.should be === "not a hash" }.should fail_with(%[expected === "not a hash", got Hash])
199
+ end
200
+ end
201
+
182
202
  describe "should be(value)" do
183
203
  it "should pass if actual.equal?(value)" do
184
204
  5.should be(5)
@@ -187,5 +207,3 @@ describe "should be(value)" do
187
207
  lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
188
208
  end
189
209
  end
190
-
191
-
@@ -0,0 +1,158 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ require 'spec/expectations/differs/default'
4
+
5
+ describe "should ==" do
6
+
7
+ it "should delegate message to target" do
8
+ subject = "apple"
9
+ subject.should_receive(:==).with("apple").and_return(true)
10
+ subject.should == "apple"
11
+ end
12
+
13
+ it "should fail when target.==(actual) returns false" do
14
+ subject = "apple"
15
+ Spec::Expectations.should_receive(:fail_with).with(%[expected "orange", got "apple" (using ==)], "orange", "apple")
16
+ subject.should == "orange"
17
+ end
18
+
19
+ end
20
+
21
+ describe "should_not ==" do
22
+
23
+ it "should delegate message to target" do
24
+ subject = "orange"
25
+ subject.should_receive(:==).with("apple").and_return(false)
26
+ subject.should_not == "apple"
27
+ end
28
+
29
+ it "should fail when target.==(actual) returns false" do
30
+ subject = "apple"
31
+ Spec::Expectations.should_receive(:fail_with).with(%[expected not == "apple", got "apple"], "apple", "apple")
32
+ subject.should_not == "apple"
33
+ end
34
+
35
+ end
36
+
37
+ describe "should ===" do
38
+
39
+ it "should delegate message to target" do
40
+ subject = "apple"
41
+ subject.should_receive(:===).with("apple").and_return(true)
42
+ subject.should === "apple"
43
+ end
44
+
45
+ it "should fail when target.===(actual) returns false" do
46
+ subject = "apple"
47
+ subject.should_receive(:===).with("orange").and_return(false)
48
+ Spec::Expectations.should_receive(:fail_with).with(%[expected "orange", got "apple" (using ===)], "orange", "apple")
49
+ subject.should === "orange"
50
+ end
51
+
52
+ end
53
+
54
+ describe "should_not ===" do
55
+
56
+ it "should delegate message to target" do
57
+ subject = "orange"
58
+ subject.should_receive(:===).with("apple").and_return(false)
59
+ subject.should_not === "apple"
60
+ end
61
+
62
+ it "should fail when target.===(actual) returns false" do
63
+ subject = "apple"
64
+ subject.should_receive(:===).with("apple").and_return(true)
65
+ Spec::Expectations.should_receive(:fail_with).with(%[expected not === "apple", got "apple"], "apple", "apple")
66
+ subject.should_not === "apple"
67
+ end
68
+
69
+ end
70
+
71
+ describe "should =~" do
72
+
73
+ it "should delegate message to target" do
74
+ subject = "foo"
75
+ subject.should_receive(:=~).with(/oo/).and_return(true)
76
+ subject.should =~ /oo/
77
+ end
78
+
79
+ it "should fail when target.=~(actual) returns false" do
80
+ subject = "fu"
81
+ subject.should_receive(:=~).with(/oo/).and_return(false)
82
+ Spec::Expectations.should_receive(:fail_with).with(%[expected =~ /oo/, got "fu"], /oo/, "fu")
83
+ subject.should =~ /oo/
84
+ end
85
+
86
+ end
87
+
88
+ describe "should_not =~" do
89
+
90
+ it "should delegate message to target" do
91
+ subject = "fu"
92
+ subject.should_receive(:=~).with(/oo/).and_return(false)
93
+ subject.should_not =~ /oo/
94
+ end
95
+
96
+ it "should fail when target.=~(actual) returns false" do
97
+ subject = "foo"
98
+ subject.should_receive(:=~).with(/oo/).and_return(true)
99
+ Spec::Expectations.should_receive(:fail_with).with(%[expected not =~ /oo/, got "foo"], /oo/, "foo")
100
+ subject.should_not =~ /oo/
101
+ end
102
+
103
+ end
104
+
105
+ describe "should >" do
106
+
107
+ it "should pass if > passes" do
108
+ 4.should > 3
109
+ end
110
+
111
+ it "should fail if > fails" do
112
+ Spec::Expectations.should_receive(:fail_with).with(%[expected > 5, got 4], 5, 4)
113
+ 4.should > 5
114
+ end
115
+
116
+ end
117
+
118
+ describe "should >=" do
119
+
120
+ it "should pass if >= passes" do
121
+ 4.should > 3
122
+ 4.should >= 4
123
+ end
124
+
125
+ it "should fail if > fails" do
126
+ Spec::Expectations.should_receive(:fail_with).with(%[expected >= 5, got 4], 5, 4)
127
+ 4.should >= 5
128
+ end
129
+
130
+ end
131
+
132
+ describe "should <" do
133
+
134
+ it "should pass if < passes" do
135
+ 4.should < 5
136
+ end
137
+
138
+ it "should fail if > fails" do
139
+ Spec::Expectations.should_receive(:fail_with).with(%[expected < 3, got 4], 3, 4)
140
+ 4.should < 3
141
+ end
142
+
143
+ end
144
+
145
+ describe "should <=" do
146
+
147
+ it "should pass if <= passes" do
148
+ 4.should <= 5
149
+ 4.should <= 4
150
+ end
151
+
152
+ it "should fail if > fails" do
153
+ Spec::Expectations.should_receive(:fail_with).with(%[expected <= 3, got 4], 3, 4)
154
+ 4.should <= 3
155
+ end
156
+
157
+ end
158
+
@@ -1,4 +1,5 @@
1
- require 'stringio'
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
2
3
  describe "CommandLine" do
3
4
  it "should run directory" do
4
5
  file = File.dirname(__FILE__) + '/../../../examples'
@@ -7,17 +8,17 @@ describe "CommandLine" do
7
8
  Spec::Runner::CommandLine.run([file], err, out, false, true)
8
9
 
9
10
  out.rewind
10
- out.read.should =~ /74 examples, 0 failures/n
11
+ out.read.should =~ /77 examples, 0 failures/n
11
12
  end
12
13
 
13
14
  it "should run file" do
14
- file = File.dirname(__FILE__) + '/../../../examples/io_processor_spec.rb'
15
+ file = File.dirname(__FILE__) + '/../../../failing_examples/predicate_example.rb'
15
16
  err = StringIO.new
16
17
  out = StringIO.new
17
18
  Spec::Runner::CommandLine.run([file], err, out, false, true)
18
19
 
19
20
  out.rewind
20
- out.read.should =~ /2 examples, 0 failures/n
21
+ out.read.should =~ /2 examples, 1 failure/n
21
22
  end
22
23
 
23
24
  it "should raise when file does not exist" do
@@ -1,5 +1,4 @@
1
- require 'stringio'
2
- require 'rbconfig'
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
2
 
4
3
  describe "DrbCommandLine without running local server" do
5
4
 
@@ -18,15 +17,23 @@ end
18
17
  describe "DrbCommandLine with local server" do
19
18
 
20
19
  unless Config::CONFIG['ruby_install_name'] == 'jruby'
21
- before :all do
22
- create_dummy_spec_file
20
+ before(:all) do
23
21
  DRb.start_service("druby://localhost:8989", Spec::Runner::CommandLine)
22
+ $drb_example_file_counter = 0
24
23
  end
25
24
 
26
- after :all do
27
- DRb.stop_service
25
+ before(:each) do
26
+ create_dummy_spec_file
27
+ $drb_example_file_counter = $drb_example_file_counter + 1
28
+ end
29
+
30
+ after(:each) do
28
31
  File.delete(@dummy_spec_filename)
29
32
  end
33
+
34
+ after(:all) do
35
+ DRb.stop_service
36
+ end
30
37
 
31
38
  it "should run against local server" do
32
39
  out = run_spec_via_druby(['--version'])
@@ -44,7 +51,7 @@ describe "DrbCommandLine with local server" do
44
51
  end
45
52
 
46
53
  def create_dummy_spec_file
47
- @dummy_spec_filename = File.expand_path(File.dirname(__FILE__)) + '/_dummy_spec.rb'
54
+ @dummy_spec_filename = File.expand_path(File.dirname(__FILE__)) + "/_dummy_spec#{$drb_example_file_counter}.rb"
48
55
  File.open(@dummy_spec_filename, 'w') do |f|
49
56
  f.write %{
50
57
  describe "DUMMY CONTEXT for 'DrbCommandLine with -c option'" do
@@ -53,7 +60,7 @@ describe "DUMMY CONTEXT for 'DrbCommandLine with -c option'" do
53
60
  end
54
61
 
55
62
  it "should be output with red bar" do
56
- violated("I wan to see a red bar!")
63
+ violated("I want to see a red bar!")
57
64
  end
58
65
  end
59
66
  }
@@ -1,6 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/../../../spec_helper.rb'
2
- require 'stringio'
2
+
3
3
  describe "HtmlFormatter" do
4
+ it_should_behave_like "Examples that have to load files"
5
+
4
6
  ['--diff', '--dry-run'].each do |opt|
5
7
  it "should produce HTML identical to the one we designed manually with #{opt}" do
6
8
  root = File.expand_path(File.dirname(__FILE__) + '/../../../..')
@@ -8,10 +10,10 @@ describe "HtmlFormatter" do
8
10
  expected_file = File.dirname(__FILE__) + "/html_formatted-#{VERSION}#{suffix}.html"
9
11
  raise "There is no HTML file with expected content for this platform: #{expected_file}" unless File.file?(expected_file)
10
12
  expected_html = File.read(expected_file)
11
- raise "There should be no absolute paths in html_formatted.html!!" if expected_html =~ /\/Users/n
13
+ raise "There should be no absolute paths in html_formatted.html!!" if (expected_html =~ /\/Users/n || expected_html =~ /\/home/n)
12
14
 
13
15
  Dir.chdir(root) do
14
- args = ['failing_examples/mocking_example.rb', 'failing_examples/diffing_spec.rb', 'examples/stubbing_example.rb', '--format', 'html', opt]
16
+ args = ['failing_examples/mocking_example.rb', 'failing_examples/diffing_spec.rb', 'examples/stubbing_example.rb', 'examples/not_yet_implemented_spec.rb', '--format', 'html', opt]
15
17
  err = StringIO.new
16
18
  out = StringIO.new
17
19
  Spec::Runner::CommandLine.run(
@@ -28,9 +30,24 @@ describe "HtmlFormatter" do
28
30
  if opt == '--diff'
29
31
  # Uncomment this line temporarily in order to overwrite the expected with actual.
30
32
  # Use with care!!!
31
- # File.open(expected_file, 'w') {|io| io.write(html)}
33
+ File.open(expected_file, 'w') {|io| io.write(html)}
34
+
35
+ doc = Hpricot(html)
36
+ backtraces = doc.search("div.backtrace").collect {|e| e.at("/pre").inner_html}
37
+ doc.search("div.backtrace").remove
38
+
39
+ expected_doc = Hpricot(expected_html)
40
+ expected_backtraces = expected_doc.search("div.backtrace").collect {|e| e.at("/pre").inner_html}
41
+ expected_doc.search("div.backtrace").remove
42
+
43
+ doc.inner_html.should == expected_doc.inner_html
32
44
 
33
- html.should == expected_html
45
+ expected_backtraces.each_with_index do |expected_line, i|
46
+ expected_path, expected_line_number, expected_suffix = expected_line.split(':')
47
+ actual_path, actual_line_number, actual_suffix = backtraces[i].split(':')
48
+ File.expand_path(actual_path).should == File.expand_path(expected_path)
49
+ actual_line_number.should == expected_line_number
50
+ end
34
51
  else
35
52
  html.should =~ /This was a dry-run/m
36
53
  end
@@ -10,7 +10,7 @@ describe "ProgressBarFormatterDryRun" do
10
10
  @formatter.dry_run = true
11
11
  end
12
12
  it "should not produce summary on dry run" do
13
- @formatter.dump_summary(3, 2, 1)
13
+ @formatter.dump_summary(3, 2, 1, 0)
14
14
  @io.string.should eql("")
15
15
 
16
16
  end