rspec 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/.document +4 -4
  2. data/{History.txt → History.rdoc} +27 -4
  3. data/Manifest.txt +18 -7
  4. data/{README.txt → README.rdoc} +0 -0
  5. data/Rakefile +16 -9
  6. data/{Ruby1.9.markdown → Ruby1.9.rdoc} +3 -3
  7. data/TODO.txt +0 -7
  8. data/Upgrade.rdoc +110 -0
  9. data/features/matchers/create_matcher.feature +40 -0
  10. data/features/matchers/create_matcher_outside_rspec.feature +39 -0
  11. data/features/pending/pending_examples.feature +5 -5
  12. data/features/step_definitions/running_rspec.rb +13 -0
  13. data/features/subject/explicit_subject.feature +31 -0
  14. data/features/subject/implicit_subject.feature +31 -0
  15. data/lib/spec/adapters/mock_frameworks/flexmock.rb +1 -0
  16. data/lib/spec/adapters/mock_frameworks/mocha.rb +1 -0
  17. data/lib/spec/adapters/mock_frameworks/rr.rb +1 -0
  18. data/lib/spec/adapters/mock_frameworks/rspec.rb +12 -10
  19. data/lib/spec/dsl.rb +0 -1
  20. data/lib/spec/dsl/main.rb +3 -3
  21. data/lib/spec/example.rb +4 -3
  22. data/lib/spec/example/example_group_factory.rb +1 -3
  23. data/lib/spec/example/example_group_methods.rb +22 -28
  24. data/lib/spec/example/example_group_proxy.rb +64 -0
  25. data/lib/spec/example/example_methods.rb +8 -11
  26. data/lib/spec/example/example_proxy.rb +42 -0
  27. data/lib/spec/example/shared_example_group.rb +1 -1
  28. data/lib/spec/example/subject.rb +14 -3
  29. data/lib/spec/expectations.rb +1 -1
  30. data/lib/spec/expectations/differs/default.rb +46 -49
  31. data/lib/spec/expectations/differs/load-diff-lcs.rb +12 -0
  32. data/lib/spec/interop/test/unit/testcase.rb +2 -2
  33. data/lib/spec/matchers.rb +49 -9
  34. data/lib/spec/matchers/be.rb +12 -15
  35. data/lib/spec/matchers/change.rb +1 -0
  36. data/lib/spec/matchers/dsl.rb +15 -0
  37. data/lib/spec/matchers/have.rb +9 -8
  38. data/lib/spec/matchers/include.rb +2 -16
  39. data/lib/spec/matchers/match_array.rb +2 -14
  40. data/lib/spec/matchers/matcher.rb +16 -11
  41. data/lib/spec/matchers/pretty.rb +36 -0
  42. data/lib/spec/matchers/raise_error.rb +9 -8
  43. data/lib/spec/matchers/simple_matcher.rb +1 -0
  44. data/lib/spec/matchers/throw_symbol.rb +1 -1
  45. data/lib/spec/mocks/argument_expectation.rb +2 -0
  46. data/lib/spec/mocks/message_expectation.rb +2 -0
  47. data/lib/spec/mocks/proxy.rb +9 -10
  48. data/lib/spec/runner.rb +1 -0
  49. data/lib/spec/runner/extensions/kernel.rb +9 -0
  50. data/lib/spec/runner/formatter/base_formatter.rb +22 -9
  51. data/lib/spec/runner/formatter/html_formatter.rb +2 -1
  52. data/lib/spec/runner/heckle_runner.rb +1 -0
  53. data/lib/spec/runner/option_parser.rb +4 -1
  54. data/lib/spec/runner/options.rb +11 -0
  55. data/lib/spec/runner/spec_parser.rb +15 -22
  56. data/lib/spec/version.rb +4 -6
  57. data/spec/autotest/autotest_helper.rb +6 -1
  58. data/spec/spec/dsl/main_spec.rb +3 -3
  59. data/spec/spec/example/example_group_factory_spec.rb +11 -23
  60. data/spec/spec/example/example_group_methods_spec.rb +45 -20
  61. data/spec/spec/example/example_group_proxy_spec.rb +63 -0
  62. data/spec/spec/example/example_group_spec.rb +15 -0
  63. data/spec/spec/example/example_methods_spec.rb +5 -35
  64. data/spec/spec/example/example_proxy_spec.rb +47 -0
  65. data/spec/spec/example/nested_example_group_spec.rb +3 -3
  66. data/spec/spec/example/shared_example_group_spec.rb +4 -4
  67. data/spec/spec/example/subject_spec.rb +77 -0
  68. data/spec/spec/matchers/be_close_spec.rb +10 -10
  69. data/spec/spec/matchers/be_instance_of_spec.rb +13 -8
  70. data/spec/spec/matchers/be_kind_of_spec.rb +10 -8
  71. data/spec/spec/{dsl/matchers_spec.rb → matchers/dsl_spec.rb} +4 -4
  72. data/spec/spec/matchers/matcher_spec.rb +53 -1
  73. data/spec/spec/matchers/matchers_spec.rb +2 -0
  74. data/spec/spec/package/bin_spec_spec.rb +4 -4
  75. data/spec/spec/runner/command_line_spec.rb +2 -2
  76. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +4 -4
  77. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +2 -2
  78. data/spec/spec/runner/formatter/html_formatted-1.8.4.html +1 -1
  79. data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +1 -1
  80. data/spec/spec/runner/formatter/html_formatted-1.8.5.html +1 -1
  81. data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +1 -1
  82. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +1 -1
  83. data/spec/spec/runner/formatter/html_formatted-1.8.7.html +1 -1
  84. data/spec/spec/runner/formatter/html_formatted-1.9.1.html +1 -1
  85. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +12 -11
  86. data/spec/spec/runner/formatter/profile_formatter_spec.rb +2 -2
  87. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +2 -2
  88. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +2 -2
  89. data/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html +1 -1
  90. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +1 -1
  91. data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +1 -1
  92. data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +1 -1
  93. data/spec/spec/runner/option_parser_spec.rb +20 -0
  94. data/spec/spec/runner/options_spec.rb +23 -1
  95. data/spec/spec/runner/reporter_spec.rb +20 -17
  96. data/spec/spec/runner/spec_parser_spec.rb +1 -1
  97. metadata +33 -15
  98. data/Upgrade.markdown +0 -63
  99. data/lib/spec/dsl/matchers.rb +0 -13
  100. data/lib/spec/example/example_description.rb +0 -15
@@ -34,7 +34,7 @@ module Spec
34
34
 
35
35
  describe "#backtrace" do
36
36
  it "returns the backtrace from where the example was defined" do
37
- example = ExampleGroup.dup.new "name"
37
+ example = ExampleGroup.dup.new ExampleProxy.new
38
38
  example.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-1}")
39
39
  end
40
40
  end
@@ -46,46 +46,16 @@ module Spec
46
46
 
47
47
  it "sends a deprecation warning" do
48
48
  Kernel.should_receive(:warn).with(/#implementation_backtrace.*deprecated.*#backtrace instead/m)
49
- example = ExampleGroup.dup.new "name"
49
+ example = ExampleGroup.dup.new ExampleProxy.new
50
50
  example.implementation_backtrace
51
51
  end
52
52
 
53
53
  it "returns the backtrace from where the example was defined" do
54
- example = ExampleGroup.dup.new "name"
54
+ example = ExampleGroup.dup.new ExampleProxy.new
55
55
  example.implementation_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-1}")
56
56
  end
57
57
  end
58
58
 
59
- describe "#subject" do
60
- before(:each) do
61
- @example_group = ExampleGroupDouble
62
- end
63
-
64
- it "should return an instance of the described class" do
65
- group = Class.new(ExampleGroupDouble).describe(Array)
66
- example = group.new("")
67
- example.subject.should == []
68
- end
69
-
70
- it "should return a Module" do
71
- group = Class.new(ExampleGroupDouble).describe(Enumerable)
72
- example = group.new("")
73
- example.subject.should == Enumerable
74
- end
75
-
76
- it "should return a string" do
77
- group = Class.new(ExampleGroupDouble).describe('foo')
78
- example = group.new("")
79
- example.subject.should == 'foo'
80
- end
81
-
82
- it "should return a number" do
83
- group = Class.new(ExampleGroupDouble).describe(15)
84
- example = group.new("")
85
- example.subject.should == 15
86
- end
87
- end
88
-
89
59
  describe "#should" do
90
60
  before(:each) do
91
61
  @example_group = Class.new(ExampleGroupDouble)
@@ -140,14 +110,14 @@ module Spec
140
110
 
141
111
  describe "#options" do
142
112
  it "should expose the options hash" do
143
- example = ExampleGroupDouble.new "name", :this => 'that' do; end
113
+ example = ExampleGroupDouble.new ExampleProxy.new("name", :this => 'that') do; end
144
114
  example.options[:this].should == 'that'
145
115
  end
146
116
  end
147
117
 
148
118
  describe "#set_instance_variables_from_hash" do
149
119
  it "preserves the options" do
150
- example = ExampleGroupDouble.new "name", :this => 'that' do; end
120
+ example = ExampleGroupDouble.new ExampleProxy.new("name", :this => 'that') do; end
151
121
  example.set_instance_variables_from_hash({:@_options => {}})
152
122
  example.options[:this].should == 'that'
153
123
  end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Spec
4
+ module Example
5
+
6
+ describe ExampleProxy do
7
+
8
+ describe "#description" do
9
+ it "provides the submitted description" do
10
+ proxy = ExampleProxy.new("the description")
11
+ proxy.description.should == "the description"
12
+ end
13
+ end
14
+
15
+ describe "#update" do
16
+ it "updates the description" do
17
+ proxy = ExampleProxy.new("old description")
18
+ proxy.update("new description")
19
+ proxy.description.should == "new description"
20
+ end
21
+ end
22
+
23
+ describe "#options" do
24
+ it "provides the submitted options" do
25
+ proxy = ExampleProxy.new(:ignore, {:these => :options})
26
+ proxy.options.should == {:these => :options}
27
+ end
28
+ end
29
+
30
+ describe "#backtrace (deprecated - use #location)" do
31
+ it "provides the location of the declaration of this group" do
32
+ proxy = ExampleProxy.new(:ignore, {}, "path/to/location:37")
33
+ proxy.backtrace.should == "path/to/location:37"
34
+ end
35
+ end
36
+
37
+ describe "#location" do
38
+ it "provides the location of the declaration of this group" do
39
+ proxy = ExampleProxy.new(:ignore, {}, "path/to/location:37")
40
+ proxy.location.should == "path/to/location:37"
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
@@ -58,11 +58,11 @@ module Spec
58
58
 
59
59
  describe "Nested Example Groups" do
60
60
  describe "description options", :other_options => "other options" do
61
- it "should have a spec_path" do
62
- self.class.options[:spec_path].should match(/#{__FILE__}/)
61
+ it "includes :location" do
62
+ self.class.options[:location].should match(/#{__FILE__}/)
63
63
  end
64
64
 
65
- it "should pass other options" do
65
+ it "includes any other options" do
66
66
  self.class.options[:other_options].should == "other options"
67
67
  end
68
68
  end
@@ -66,12 +66,12 @@ module Spec
66
66
  SharedExampleGroup.register(
67
67
  "shared example_group",
68
68
  :shared => true,
69
- :spec_path => "/my/spec/a/../shared.rb"
69
+ :location => "/my/spec/a/../shared.rb"
70
70
  )
71
71
  SharedExampleGroup.register(
72
72
  "shared example_group",
73
73
  :shared => true,
74
- :spec_path => "/my/spec/b/../shared.rb"
74
+ :location => "/my/spec/b/../shared.rb"
75
75
  )
76
76
  end
77
77
 
@@ -79,13 +79,13 @@ module Spec
79
79
  SharedExampleGroup.register(
80
80
  "shared example_group",
81
81
  :shared => true,
82
- :spec_path => "/my/spec/a/shared.rb"
82
+ :location => "/my/spec/a/shared.rb"
83
83
  )
84
84
  lambda do
85
85
  SharedExampleGroup.register(
86
86
  "shared example_group",
87
87
  :shared => true,
88
- :spec_path => "/my/spec/b/shared.rb"
88
+ :location => "/my/spec/b/shared.rb"
89
89
  )
90
90
  end.should raise_error(ArgumentError, /already exists/)
91
91
  end
@@ -0,0 +1,77 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Spec
4
+ module Example
5
+ describe "implicit subject" do
6
+ describe "with a class" do
7
+ it "returns an instance of the class" do
8
+ group = Class.new(ExampleGroupDouble).describe(Array)
9
+ example = group.new(ExampleProxy.new)
10
+ example.subject.should == []
11
+ end
12
+ end
13
+
14
+ describe "with a Module" do
15
+ it "returns the Module" do
16
+ group = Class.new(ExampleGroupDouble).describe(Enumerable)
17
+ example = group.new(ExampleProxy.new)
18
+ example.subject.should == Enumerable
19
+ end
20
+ end
21
+
22
+ describe "with a string" do
23
+ it "return the string" do
24
+ group = Class.new(ExampleGroupDouble).describe('foo')
25
+ example = group.new(ExampleProxy.new)
26
+ example.subject.should == 'foo'
27
+ end
28
+ end
29
+
30
+ describe "with a number" do
31
+ it "returns the number" do
32
+ group = Class.new(ExampleGroupDouble).describe(15)
33
+ example = group.new(ExampleProxy.new)
34
+ example.subject.should == 15
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ describe "explicit subject" do
41
+ describe "defined in a top level group" do
42
+ it "replaces the implicit subject in that group" do
43
+ group = Class.new(ExampleGroupDouble).describe(Array)
44
+ group.subject { [1,2,3] }
45
+ example = group.new(ExampleProxy.new)
46
+ example.subject.should == [1,2,3]
47
+ end
48
+ end
49
+
50
+ describe "defined in a top level group" do
51
+ it "is available in a nested group (subclass)" do
52
+ klass = Class.new do
53
+ extend Spec::Example::Subject::ExampleGroupMethods
54
+ include Spec::Example::Subject::ExampleMethods
55
+ class << self
56
+ def described_class
57
+ Array
58
+ end
59
+ end
60
+ def described_class
61
+ self.class.described_class
62
+ end
63
+
64
+ subject {
65
+ [1,2,3]
66
+ }
67
+ end
68
+
69
+ subclass = Class.new(klass)
70
+
71
+ object = subclass.new
72
+ object.subject.should == [1,2,3]
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,29 +1,29 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
  module Spec
3
3
  module Matchers
4
- describe "be_close" do
5
- it "should match when value == target" do
4
+ describe "[actual.should] be_close(expected, delta)" do
5
+ it "matches when actual == expected" do
6
6
  be_close(5.0, 0.5).matches?(5.0).should be_true
7
7
  end
8
- it "should match when value < (target + delta)" do
8
+ it "matches when actual < (expected + delta)" do
9
9
  be_close(5.0, 0.5).matches?(5.49).should be_true
10
10
  end
11
- it "should match when value > (target - delta)" do
11
+ it "matches when actual > (expected - delta)" do
12
12
  be_close(5.0, 0.5).matches?(4.51).should be_true
13
13
  end
14
- it "should not match when value == (target - delta)" do
14
+ it "does not match when actual == (expected - delta)" do
15
15
  be_close(5.0, 0.5).matches?(4.5).should be_false
16
16
  end
17
- it "should not match when value < (target - delta)" do
17
+ it "does not match when actual < (expected - delta)" do
18
18
  be_close(5.0, 0.5).matches?(4.49).should be_false
19
19
  end
20
- it "should not match when value == (target + delta)" do
20
+ it "does not match when actual == (expected + delta)" do
21
21
  be_close(5.0, 0.5).matches?(5.5).should be_false
22
22
  end
23
- it "should not match when value > (target + delta)" do
23
+ it "does not match when actual > (expected + delta)" do
24
24
  be_close(5.0, 0.5).matches?(5.51).should be_false
25
25
  end
26
- it "should provide a useful failure message" do
26
+ it "provides a failure message for should" do
27
27
  #given
28
28
  matcher = be_close(5.0, 0.5)
29
29
  #when
@@ -31,7 +31,7 @@ module Spec
31
31
  #then
32
32
  matcher.failure_message_for_should.should == "expected 5.0 +/- (< 0.5), got 5.51"
33
33
  end
34
- it "should describe itself" do
34
+ it "provides a description" do
35
35
  matcher = be_close(5.0, 0.5)
36
36
  matcher.matches?(5.1)
37
37
  matcher.description.should == "be close to 5.0 (within +- 0.5)"
@@ -3,27 +3,32 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  module Spec
4
4
  module Matchers
5
5
  [:be_instance_of, :be_an_instance_of].each do |method|
6
- describe "#{method}" do
7
- it "passes if object is instance of given class" do
6
+ describe "actual.should #{method}(expected)" do
7
+ it "passes if actual is instance of expected class" do
8
8
  5.should send(method, Fixnum)
9
9
  end
10
10
 
11
- it "failse if object is instance of subclass of expected class" do
11
+ it "fails if actual is instance of subclass of expected class" do
12
12
  lambda { 5.should send(method, Numeric) }.should fail_with(%Q{expected instance of Numeric, got 5})
13
13
  end
14
14
 
15
- it "fails with failure message unless object is kind of given class" do
15
+ it "fails with failure message for should unless actual is instance of expected class" do
16
16
  lambda { "foo".should send(method, Array) }.should fail_with(%Q{expected instance of Array, got "foo"})
17
17
  end
18
18
 
19
- it "fails with negative failure message if object is kind of given class" do
20
- lambda { "foo".should_not send(method, String) }.should fail_with(%Q{expected "foo" not to be an instance of String})
21
- end
22
-
23
19
  it "provides a description" do
24
20
  Spec::Matchers::BeInstanceOf.new(Class).description.should == "be an instance of Class"
25
21
  end
26
22
  end
23
+
24
+ describe "actual.should_not #{method}(expected)" do
25
+
26
+ it "fails with failure message for should_not if actual is instance of expected class" do
27
+ lambda { "foo".should_not send(method, String) }.should fail_with(%Q{expected "foo" not to be an instance of String})
28
+ end
29
+
30
+ end
31
+
27
32
  end
28
33
  end
29
34
  end
@@ -3,27 +3,29 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  module Spec
4
4
  module Matchers
5
5
  [:be_kind_of, :be_a_kind_of].each do |method|
6
- describe "#{method}" do
7
- it "passes if object is instance of given class" do
6
+ describe "actual.should #{method}(expected)" do
7
+ it "passes if actual is instance of expected class" do
8
8
  5.should send(method, Fixnum)
9
9
  end
10
10
 
11
- it "passes if object is instance of subclass of expected class" do
11
+ it "passes if actual is instance of subclass of expected class" do
12
12
  5.should send(method, Numeric)
13
13
  end
14
14
 
15
- it "fails with failure message unless object is kind of given class" do
15
+ it "fails with failure message for should unless actual is kind of expected class" do
16
16
  lambda { "foo".should send(method, Array) }.should fail_with(%Q{expected kind of Array, got "foo"})
17
17
  end
18
18
 
19
- it "fails with negative failure message if object is kind of given class" do
20
- lambda { "foo".should_not send(method, String) }.should fail_with(%Q{expected "foo" not to be a kind of String})
21
- end
22
-
23
19
  it "provides a description" do
24
20
  Spec::Matchers::BeKindOf.new(Class).description.should == "be a kind of Class"
25
21
  end
26
22
  end
23
+
24
+ describe "actual.should_not #{method}(expected)" do
25
+ it "fails with failure message for should_not if actual is kind of expected class" do
26
+ lambda { "foo".should_not send(method, String) }.should fail_with(%Q{expected "foo" not to be a kind of String})
27
+ end
28
+ end
27
29
  end
28
30
  end
29
31
  end
@@ -1,15 +1,15 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  module Spec
4
- module DSL
5
- module Matchers
4
+ module Matchers
5
+ module DSL
6
6
  describe "#create" do
7
7
  it "creates a method that initializes a new matcher with the submitted name and expected arg" do
8
8
  # FIXME - this expects new to be called, but we need something
9
9
  # more robust - that expects new to be called with a specific
10
10
  # block (lambda, proc, whatever)
11
11
  mod = Module.new
12
- mod.extend Spec::DSL::Matchers
12
+ mod.extend Spec::Matchers::DSL
13
13
  mod.create(:foo)
14
14
 
15
15
  obj = Object.new
@@ -90,8 +90,60 @@ module Spec
90
90
  end
91
91
  end
92
92
 
93
- context "matching with overrides" do
93
+ context "with no args" do
94
+ before(:each) do
95
+ @matcher = Spec::Matchers::Matcher.new(:matcher_name) do
96
+ match do |actual|
97
+ actual == 5
98
+ end
99
+ end
100
+ end
101
+
102
+ it "matches" do
103
+ @matcher.matches?(5).should be_true
104
+ end
105
+
106
+ it "describes" do
107
+ @matcher.description.should == "matcher name"
108
+ end
94
109
  end
110
+
111
+ context "with 1 arg" do
112
+ before(:each) do
113
+ @matcher = Spec::Matchers::Matcher.new(:matcher_name, 1) do |expected|
114
+ match do |actual|
115
+ actual == 5 && expected == 1
116
+ end
117
+ end
118
+ end
119
+
120
+ it "matches" do
121
+ @matcher.matches?(5).should be_true
122
+ end
123
+
124
+ it "describes" do
125
+ @matcher.description.should == "matcher name 1"
126
+ end
127
+ end
128
+
129
+ context "with multiple args" do
130
+ before(:each) do
131
+ @matcher = Spec::Matchers::Matcher.new(:matcher_name, 1, 2, 3, 4) do |a,b,c,d|
132
+ match do |sum|
133
+ a + b + c + d == sum
134
+ end
135
+ end
136
+ end
137
+
138
+ it "matches" do
139
+ @matcher.matches?(10).should be_true
140
+ end
141
+
142
+ it "describes" do
143
+ @matcher.description.should == "matcher name 1, 2, 3, and 4"
144
+ end
145
+ end
146
+
95
147
  end
96
148
  end
97
149
  end