rspec 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,15 @@
1
+ == Version 1.0.4
2
+ The getting ready for JRuby release.
3
+
4
+ * Fixed [#11181] behaviour_type scoping of config.before(:each) is not working
5
+ * added mock argument constraint matchers (anything(), boolean(), an_instance_of(Type)) which work with rspec or mocha
6
+ * added mock argument constraint matchers (any_args(), no_args()) which only work with rspec
7
+ * deprecated rspec's symbol mock argument constraint matchers (:any_args, :no_args, :anything, :boolean, :numeric, :string)
8
+ * Added tarball of rspec_on_rails to the release build to support folks working behind a firewall that blocks svn access.
9
+ * Fixed [#11137] rspec incorrectly handles flash after resetting the session
10
+ * Fixed [#11143] Views code for ActionController::Base#render broke between 1.0.0 and 1.0.3 on Rails Edge r6731
11
+ * Added raise_controller_errors for controller examples in Spec::Rails
12
+
1
13
  == Version 1.0.3
2
14
  Bug fixes.
3
15
 
@@ -103,6 +103,6 @@
103
103
  # * RSpec should be able to access TestCase methods
104
104
  # * RSpec should be able to accept included modules
105
105
 
106
- Finished in 0.024365 seconds
106
+ Finished in 0.026702 seconds
107
107
 
108
108
  77 examples, 0 failures, 2 not implemented
data/Rakefile CHANGED
@@ -157,19 +157,18 @@ task :tag do
157
157
  from = `svn info #{File.dirname(__FILE__)}`.match(/URL: (.*)\/rspec/n)[1]
158
158
  to = from.gsub(/trunk/, "tags/#{Spec::VERSION::TAG}")
159
159
  current = from.gsub(/trunk/, "tags/CURRENT")
160
- tag_cmd = "svn cp #{from} #{to} -m \"Tag release #{Spec::VERSION::FULL_VERSION}\""
161
- remove_current_cmd = "svn rm #{current}"
162
- commit_current_cmd = "svn ci #{current} -m \"Remove tags/CURRENT\""
163
- create_current_cmd = "svn cp #{to} #{current} -m \"Copy #{Spec::VERSION::TAG} to tags/CURRENT\""
164
- raise "Can't tag to the same place: #{tag_cmd}" if to == from
160
+
165
161
  puts "Creating tag in SVN"
166
- `#{tag_cmd}`
162
+ tag_cmd = "svn cp #{from} #{to} -m \"Tag release #{Spec::VERSION::FULL_VERSION}\""
163
+ `#{tag_cmd}` ; raise "ERROR: #{tag_cmd}" unless $? == 0
164
+
167
165
  puts "Removing CURRENT"
168
- `#{remove_current_cmd}`
169
- `#{commit_current_cmd}`
166
+ remove_current_cmd = "svn rm #{current} -m \"Remove tags/CURRENT\""
167
+ `#{remove_current_cmd}` ; raise "ERROR: #{remove_current_cmd}" unless $? == 0
168
+
170
169
  puts "Re-Creating CURRENT"
171
- `#{create_current_cmd}`
172
- raise "Tagging failed" unless $? == 0
170
+ create_current_cmd = "svn cp #{to} #{current} -m \"Copy #{Spec::VERSION::TAG} to tags/CURRENT\""
171
+ `#{create_current_cmd}` ; "ERROR: #{create_current_cmd}" unless $? == 0
173
172
  end
174
173
 
175
174
  desc "Run this task before you commit. You should see 'OK TO COMMIT'"
@@ -210,6 +209,17 @@ task :archive_website => [:verify_user, :website] do
210
209
  publisher.upload
211
210
  end
212
211
 
212
+ desc "Package the Rails plugin"
213
+ task :package_rspec_on_rails do
214
+ mkdir 'pkg' rescue nil
215
+ rm_rf 'pkg/rspec_on_rails' rescue nil
216
+ `svn export ../rspec_on_rails pkg/rspec_on_rails-#{PKG_VERSION}`
217
+ Dir.chdir 'pkg' do
218
+ `tar cvzf rspec_on_rails-#{PKG_VERSION}.tgz rspec_on_rails-#{PKG_VERSION}`
219
+ end
220
+ end
221
+ task :pkg => :package_rspec_on_rails
222
+
213
223
  desc "Package the RSpec.tmbundle"
214
224
  task :package_tmbundle do
215
225
  mkdir 'pkg' rescue nil
@@ -31,8 +31,12 @@ module Spec
31
31
  end
32
32
 
33
33
  private
34
-
34
+
35
35
  def init_description(*args)
36
+ unless self.class == Behaviour
37
+ args << {} unless Hash === args.last
38
+ args.last[:behaviour_class] = self.class
39
+ end
36
40
  @description = Description.new(*args)
37
41
  end
38
42
 
@@ -118,12 +122,12 @@ module Spec
118
122
  end
119
123
  end
120
124
 
121
- protected
122
-
123
125
  def behaviour_type #:nodoc:
124
126
  @description[:behaviour_type]
125
127
  end
126
128
 
129
+ protected
130
+
127
131
  # Messages that this class does not understand
128
132
  # are passed directly to the @eval_module.
129
133
  def method_missing(sym, *args, &block)
@@ -71,10 +71,16 @@ module Spec
71
71
  # predicate_matchers[matcher_name] = [method1_on_object, method2_on_object]
72
72
  #
73
73
  # Dynamically generates a custom matcher that will match
74
- # a predicate on your class. RSpec uses this itself to allow you
75
- # to say File.should exist("path/to/file").
74
+ # a predicate on your class. RSpec provides a couple of these
75
+ # out of the box:
76
76
  #
77
- # == Example
77
+ # exist (or state expectations)
78
+ # File.should exist("path/to/file")
79
+ #
80
+ # an_instance_of (for mock argument constraints)
81
+ # mock.should_receive(:message).with(an_instance_of(String))
82
+ #
83
+ # == Examples
78
84
  #
79
85
  # class Fish
80
86
  # def can_swim?
@@ -89,7 +95,7 @@ module Spec
89
95
  # end
90
96
  # end
91
97
  def predicate_matchers
92
- @predicate_matchers ||= {:exist => :exist?}
98
+ @predicate_matchers ||= {:exist => :exist?, :an_instance_of => :is_a?}
93
99
  end
94
100
 
95
101
  def define_predicate_matchers(hash=nil) # :nodoc:
@@ -112,7 +118,7 @@ module Spec
112
118
  end
113
119
 
114
120
  # Alias for it.
115
- def specify(description, opts={}, &block)
121
+ def specify(description=:__generate_description, opts={}, &block)
116
122
  it(description, opts, &block)
117
123
  end
118
124
 
@@ -18,8 +18,9 @@ module Spec
18
18
 
19
19
  def initialize(*args)
20
20
  args, @options = args_and_options(*args)
21
- @described_type = args.first unless args.first.is_a?(String)
22
- @description = self.class.generate_description(*args)
21
+ init_behaviour_type(@options)
22
+ init_described_type(args)
23
+ init_description(*args)
23
24
  end
24
25
 
25
26
  def [](key)
@@ -40,6 +41,28 @@ module Spec
40
41
  @description == value
41
42
  end
42
43
  end
44
+
45
+ private
46
+ def init_behaviour_type(options)
47
+ # NOTE - BE CAREFUL IF CHANGING THIS NEXT LINE:
48
+ # this line is as it is to satisfy JRuby - the original version
49
+ # read, simply: "if options[:behaviour_class]", which passed against ruby, but failed against jruby
50
+ if options[:behaviour_class] && options[:behaviour_class].ancestors.include?(Behaviour)
51
+ options[:behaviour_type] = parse_behaviour_type(@options[:behaviour_class])
52
+ end
53
+ end
54
+
55
+ def init_description(*args)
56
+ @description = self.class.generate_description(*args)
57
+ end
58
+
59
+ def init_described_type(args)
60
+ @described_type = args.first unless args.first.is_a?(String)
61
+ end
62
+
63
+ def parse_behaviour_type(behaviour_class)
64
+ behaviour_class.to_s.split("::").reverse[0].gsub!('Behaviour', '').downcase.to_sym
65
+ end
43
66
 
44
67
  end
45
68
  end
@@ -129,13 +129,12 @@ module Spec
129
129
  # In addition, Spec::Mocks adds some keyword Symbols that you can use to
130
130
  # specify certain kinds of arguments:
131
131
  #
132
- # my_mock.should_receive(:sym).with(:no_args)
133
- # my_mock.should_receive(:sym).with(:any_args)
134
- # my_mock.should_receive(:sym).with(1, :numeric, "b") #2nd argument can any type of Numeric
135
- # my_mock.should_receive(:sym).with(1, :boolean, "b") #2nd argument can true or false
136
- # my_mock.should_receive(:sym).with(1, :string, "b") #2nd argument can be any String
132
+ # my_mock.should_receive(:sym).with(no_args())
133
+ # my_mock.should_receive(:sym).with(any_args())
134
+ # my_mock.should_receive(:sym).with(1, an_instance_of(Numeric), "b") #2nd argument can any type of Numeric
135
+ # my_mock.should_receive(:sym).with(1, boolean(), "b") #2nd argument can true or false
137
136
  # my_mock.should_receive(:sym).with(1, /abc/, "b") #2nd argument can be any String matching the submitted Regexp
138
- # my_mock.should_receive(:sym).with(1, :anything, "b") #2nd argument can be anything at all
137
+ # my_mock.should_receive(:sym).with(1, anything(), "b") #2nd argument can be anything at all
139
138
  # my_mock.should_receive(:sym).with(1, ducktype(:abs, :div), "b")
140
139
  # #2nd argument can be object that responds to #abs and #div
141
140
  #
@@ -4,9 +4,24 @@ module Spec
4
4
 
5
5
  # Shortcut for creating an instance of Spec::Mocks::DuckTypeArgConstraint
6
6
  def duck_type(*args)
7
- return Spec::Mocks::DuckTypeArgConstraint.new(*args)
7
+ DuckTypeArgConstraint.new(*args)
8
8
  end
9
9
 
10
+ def any_args
11
+ AnyArgsConstraint.new
12
+ end
13
+
14
+ def anything
15
+ AnyArgConstraint.new(nil)
16
+ end
17
+
18
+ def boolean
19
+ BooleanArgConstraint.new(nil)
20
+ end
21
+
22
+ def no_args
23
+ NoArgsConstraint.new
24
+ end
10
25
  end
11
26
  end
12
27
  end
@@ -36,11 +36,32 @@ module Spec
36
36
  def initialize(ignore)
37
37
  end
38
38
 
39
+ def ==(other)
40
+ true
41
+ end
42
+
43
+ # TODO - need this?
39
44
  def matches?(value)
40
45
  true
41
46
  end
42
47
  end
43
48
 
49
+ class AnyArgsConstraint
50
+ def description
51
+ "any args"
52
+ end
53
+ end
54
+
55
+ class NoArgsConstraint
56
+ def description
57
+ "no args"
58
+ end
59
+
60
+ def ==(args)
61
+ args == []
62
+ end
63
+ end
64
+
44
65
  class NumericArgConstraint
45
66
  def initialize(ignore)
46
67
  end
@@ -54,6 +75,10 @@ module Spec
54
75
  def initialize(ignore)
55
76
  end
56
77
 
78
+ def ==(value)
79
+ matches?(value)
80
+ end
81
+
57
82
  def matches?(value)
58
83
  return true if value.is_a?(TrueClass)
59
84
  return true if value.is_a?(FalseClass)
@@ -94,8 +119,14 @@ module Spec
94
119
 
95
120
  def initialize(args)
96
121
  @args = args
97
- if [:any_args] == args then @expected_params = nil
98
- elsif [:no_args] == args then @expected_params = []
122
+ if [:any_args] == args
123
+ @expected_params = nil
124
+ warn_deprecated(:any_args.inspect, "any_args()")
125
+ elsif args.length == 1 && args[0].is_a?(AnyArgsConstraint) then @expected_params = nil
126
+ elsif [:no_args] == args
127
+ @expected_params = []
128
+ warn_deprecated(:no_args.inspect, "no_args()")
129
+ elsif args.length == 1 && args[0].is_a?(NoArgsConstraint) then @expected_params = []
99
130
  else @expected_params = process_arg_constraints(args)
100
131
  end
101
132
  end
@@ -106,8 +137,25 @@ module Spec
106
137
  end
107
138
  end
108
139
 
140
+ def warn_deprecated(deprecated_method, instead)
141
+ STDERR.puts "The #{deprecated_method} constraint is deprecated. Use #{instead} instead."
142
+ end
143
+
109
144
  def convert_constraint(constraint)
110
- return @@constraint_classes[constraint].new(constraint) if constraint.is_a?(Symbol)
145
+ if [:anything, :numeric, :boolean, :string].include?(constraint)
146
+ case constraint
147
+ when :anything
148
+ instead = "anything()"
149
+ when :boolean
150
+ instead = "boolean()"
151
+ when :numeric
152
+ instead = "an_instance_of(Numeric)"
153
+ when :string
154
+ instead = "an_instance_of(String)"
155
+ end
156
+ warn_deprecated(constraint.inspect, instead)
157
+ return @@constraint_classes[constraint].new(constraint)
158
+ end
111
159
  return MatcherConstraint.new(constraint) if is_matcher?(constraint)
112
160
  return RegexpArgConstraint.new(constraint) if constraint.is_a?(Regexp)
113
161
  return LiteralArgConstraint.new(constraint)
@@ -17,8 +17,7 @@ module Spec
17
17
  end
18
18
 
19
19
  def raise_unexpected_message_args_error(expectation, *args)
20
- #this is either :no_args or an Array
21
- expected_args = (expectation.expected_args == :no_args ? "(no args)" : format_args(*expectation.expected_args))
20
+ expected_args = format_args(*expectation.expected_args)
22
21
  actual_args = args.empty? ? "(no args)" : format_args(*args)
23
22
  __raise "#{intro} expected #{expectation.sym.inspect} with #{expected_args} but received it with #{actual_args}"
24
23
  end
@@ -13,7 +13,7 @@ module Spec
13
13
  @return_block = lambda {}
14
14
  @received_count = 0
15
15
  @expected_received_count = expected_received_count
16
- @args_expectation = ArgumentExpectation.new([:any_args])
16
+ @args_expectation = ArgumentExpectation.new([AnyArgsConstraint.new])
17
17
  @consecutive = false
18
18
  @exception_to_raise = nil
19
19
  @symbol_to_throw = nil
@@ -3,11 +3,11 @@ module Spec
3
3
  unless defined? MAJOR
4
4
  MAJOR = 1
5
5
  MINOR = 0
6
- TINY = 3
6
+ TINY = 4
7
7
  RELEASE_CANDIDATE = nil
8
8
 
9
- # RANDOM_TOKEN: 0.135908585165873
10
- REV = "$LastChangedRevision: 2035 $".match(/LastChangedRevision: (\d+)/)[1]
9
+ # RANDOM_TOKEN: 0.691783562403103
10
+ REV = "$LastChangedRevision: 2054 $".match(/LastChangedRevision: (\d+)/)[1]
11
11
 
12
12
  STRING = [MAJOR, MINOR, TINY].join('.')
13
13
  TAG = "REL_#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('_')}".upcase.gsub(/\.|-/, '_')
@@ -312,8 +312,8 @@ module Spec
312
312
  end
313
313
 
314
314
  it "after callbacks are ordered from local to global" do
315
- @reporter.should_receive(:add_behaviour).with :any_args
316
- @reporter.should_receive(:example_finished).with :any_args
315
+ @reporter.should_receive(:add_behaviour).with any_args()
316
+ @reporter.should_receive(:example_finished).with any_args()
317
317
 
318
318
  fiddle = []
319
319
  super_class = Class.new do
@@ -400,8 +400,8 @@ module Spec
400
400
  end
401
401
 
402
402
  it "should have accessible instance methods from included module" do
403
- @reporter.should_receive(:add_behaviour).with :any_args
404
- @reporter.should_receive(:example_finished).with :any_args
403
+ @reporter.should_receive(:add_behaviour).with any_args()
404
+ @reporter.should_receive(:example_finished).with any_args()
405
405
 
406
406
  mod1_method_called = false
407
407
  mod1 = Module.new do
@@ -598,6 +598,10 @@ module Spec
598
598
  BehaviourSubclass.new(Example){}.described_type.should == Example
599
599
  end
600
600
 
601
+ it "should figure out its behaviour_type based on its name ()" do
602
+ BehaviourSubclass.new(Object){}.behaviour_type.should == :subclass
603
+ end
604
+
601
605
  # TODO - add an example about shared behaviours
602
606
  end
603
607
 
@@ -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, false)
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
 
@@ -4,12 +4,12 @@ module Spec
4
4
  module DSL
5
5
  describe Behaviour, ", with :shared => true" do
6
6
 
7
- before do
7
+ before(:each) do
8
8
  @formatter = Spec::Mocks::Mock.new("formatter", :null_object => true)
9
9
  @behaviour = behaviour_class.new("behaviour") {}
10
10
  end
11
11
 
12
- after do
12
+ after(:each) do
13
13
  @formatter.rspec_verify
14
14
  @behaviour_class = nil
15
15
  $shared_behaviours.clear unless $shared_behaviours.nil?
@@ -24,11 +24,15 @@ module Spec
24
24
  @behaviour_class
25
25
  end
26
26
 
27
- def make_shared_behaviour(name, opts, &block)
28
- behaviour = behaviour_class.new(name, opts, &block)
27
+ def make_shared_behaviour(name, opts=nil, &block)
28
+ behaviour = behaviour_class.new(name, :shared => true, &block)
29
29
  behaviour_class.add_shared_behaviour(behaviour)
30
30
  behaviour
31
31
  end
32
+
33
+ def non_shared_behaviour()
34
+ @non_shared_behaviour ||= behaviour_class.new("behaviour") {}
35
+ end
32
36
 
33
37
  it "should accept an optional options hash" do
34
38
  lambda { behaviour_class.new("context") {} }.should_not raise_error(Exception)
@@ -36,49 +40,52 @@ module Spec
36
40
  end
37
41
 
38
42
  it "should return all shared behaviours" do
39
- make_shared_behaviour("b1", :shared => true) {}
40
- make_shared_behaviour("b2", :shared => true) {}
43
+ b1 = make_shared_behaviour("b1", :shared => true) {}
44
+ b2 = make_shared_behaviour("b2", :shared => true) {}
45
+
46
+ b1.should_not be(nil)
47
+ b2.should_not be(nil)
41
48
 
42
- behaviour_class.find_shared_behaviour("b1").should_not be_nil
43
- behaviour_class.find_shared_behaviour("b2").should_not be_nil
49
+ behaviour_class.find_shared_behaviour("b1").should equal(b1)
50
+ behaviour_class.find_shared_behaviour("b2").should equal(b2)
44
51
  end
45
52
 
46
53
  it "should be shared when configured as shared" do
47
- behaviour = make_shared_behaviour("context", :shared => true) {}
54
+ behaviour = make_shared_behaviour("behaviour") {}
48
55
  behaviour.should be_shared
49
56
  end
50
57
 
51
58
  it "should not be shared when not configured as shared" do
52
- @behaviour.should_not be_shared
59
+ non_shared_behaviour.should_not be_shared
53
60
  end
54
61
 
55
62
  it "should raise if run when shared" do
56
- behaviour = make_shared_behaviour("context", :shared => true) {}
57
- $spec_ran = false
58
- behaviour.it("test") {$spec_ran = true}
63
+ behaviour = make_shared_behaviour("context") {}
64
+ $example_ran = false
65
+ behaviour.it("test") {$example_ran = true}
59
66
  lambda { behaviour.run(@formatter) }.should raise_error
60
- $spec_ran.should be_false
67
+ $example_ran.should be_false
61
68
  end
62
69
 
63
70
  it "should contain examples when shared" do
64
- shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
71
+ shared_behaviour = make_shared_behaviour("shared behaviour") {}
65
72
  shared_behaviour.it("shared example") {}
66
73
  shared_behaviour.number_of_examples.should == 1
67
74
  end
68
75
 
69
76
  it "should complain when adding a second shared behaviour with the same description" do
70
- make_shared_behaviour("shared behaviour", :shared => true) {}
71
- lambda { make_shared_behaviour("shared behaviour", :shared => true) {} }.should raise_error(ArgumentError)
77
+ make_shared_behaviour("shared behaviour") {}
78
+ lambda { make_shared_behaviour("shared behaviour") {} }.should raise_error(ArgumentError)
72
79
  end
73
80
 
74
81
  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) {}
82
+ behaviour = behaviour_class.new("shared behaviour") {}
76
83
  behaviour_class.add_shared_behaviour(behaviour)
77
84
  behaviour_class.add_shared_behaviour(behaviour)
78
85
  end
79
86
 
80
87
  it "should add examples to current behaviour when calling it_should_behave_like" do
81
- shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
88
+ shared_behaviour = make_shared_behaviour("shared behaviour") {}
82
89
  shared_behaviour.it("shared example") {}
83
90
  shared_behaviour.it("shared example 2") {}
84
91
 
@@ -90,7 +97,7 @@ module Spec
90
97
 
91
98
  it "should run shared examples" do
92
99
  shared_example_ran = false
93
- shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
100
+ shared_behaviour = make_shared_behaviour("shared behaviour") {}
94
101
  shared_behaviour.it("shared example") { shared_example_ran = true }
95
102
 
96
103
  example_ran = false
@@ -105,7 +112,7 @@ module Spec
105
112
  it "should run setup and teardown from shared behaviour" do
106
113
  shared_setup_ran = false
107
114
  shared_teardown_ran = false
108
- shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
115
+ shared_behaviour = make_shared_behaviour("shared behaviour") {}
109
116
  shared_behaviour.before { shared_setup_ran = true }
110
117
  shared_behaviour.after { shared_teardown_ran = true }
111
118
  shared_behaviour.it("shared example") { shared_example_ran = true }
@@ -123,7 +130,7 @@ module Spec
123
130
  it "should run before(:all) and after(:all) only once from shared behaviour" do
124
131
  shared_before_all_run_count = 0
125
132
  shared_after_all_run_count = 0
126
- shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
133
+ shared_behaviour = make_shared_behaviour("shared behaviour") {}
127
134
  shared_behaviour.before(:all) { shared_before_all_run_count += 1}
128
135
  shared_behaviour.after(:all) { shared_after_all_run_count += 1}
129
136
  shared_behaviour.it("shared example") { shared_example_ran = true }
@@ -139,10 +146,10 @@ module Spec
139
146
  end
140
147
 
141
148
  it "should include modules, included into shared behaviour, into current behaviour" do
142
- @formatter.should_receive(:add_behaviour).with :any_args
143
- @formatter.should_receive(:example_finished).twice.with :any_args
149
+ @formatter.should_receive(:add_behaviour).with(any_args)
150
+ @formatter.should_receive(:example_finished).twice.with(any_args)
144
151
 
145
- shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
152
+ shared_behaviour = make_shared_behaviour("shared behaviour") {}
146
153
  shared_behaviour.it("shared example") { shared_example_ran = true }
147
154
 
148
155
  mod1_method_called = false
@@ -174,7 +181,7 @@ module Spec
174
181
  end
175
182
 
176
183
  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
184
+ shared_behaviour = make_shared_behaviour("shared behaviour xyz") do
178
185
  def a_shared_helper_method
179
186
  "this got defined in a shared behaviour"
180
187
  end
@@ -190,7 +197,7 @@ module Spec
190
197
  end
191
198
 
192
199
  it "should error if told to inherit from a class" do
193
- shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
200
+ shared_behaviour = make_shared_behaviour("shared behaviour") {}
194
201
  shared_behaviour.it("shared example") { shared_example_ran = true }
195
202
  lambda { shared_behaviour.inherit Object }.should raise_error(ArgumentError)
196
203
  end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ describe "The anything() mock argument constraint matcher" do
4
+ specify { anything.should == Object.new }
5
+ specify { anything.should == Class }
6
+ specify { anything.should == 1 }
7
+ specify { anything.should == "a string" }
8
+ specify { anything.should == :a_symbol }
9
+ end
10
+
11
+ describe "The boolean() mock argument constraint matcher" do
12
+ specify { boolean.should == true }
13
+ specify { boolean.should == false }
14
+ specify { boolean.should_not == Object.new }
15
+ specify { boolean.should_not == Class }
16
+ specify { boolean.should_not == 1 }
17
+ specify { boolean.should_not == "a string" }
18
+ specify { boolean.should_not == :a_symbol }
19
+ end
20
+
21
+ describe "The an_instance_of() mock argument constraint matcher" do
22
+ # NOTE - this is implemented as a predicate_matcher - see behaviour.rb
23
+ specify { an_instance_of(String).should == "string" }
24
+ end
@@ -2,42 +2,42 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  module Spec
4
4
  module Mocks
5
- describe "FailingMockArgumentConstraints" do
6
- before do
5
+ describe "failing MockArgumentConstraints" do
6
+ before(:each) do
7
7
  @mock = mock("test mock")
8
8
  @reporter = Mock.new("reporter", :null_object => true)
9
9
  end
10
10
 
11
- after do
11
+ after(:each) do
12
12
  @mock.rspec_reset
13
13
  end
14
-
15
- it "should reject goose when expecting a duck" do
16
- @mock.should_receive(:random_call).with(DuckTypeArgConstraint.new(:abs, :div))
17
- lambda { @mock.random_call("I don't respond to :abs or :div") }.should raise_error(MockExpectationError)
18
- end
19
-
14
+
20
15
  it "should reject non boolean" do
21
- @mock.should_receive(:random_call).with(:boolean)
16
+ @mock.should_receive(:random_call).with(boolean())
22
17
  lambda do
23
18
  @mock.random_call("false")
24
19
  end.should raise_error(MockExpectationError)
25
20
  end
26
-
21
+
27
22
  it "should reject non numeric" do
28
- @mock.should_receive(:random_call).with(:numeric)
23
+ @mock.should_receive(:random_call).with(an_instance_of(Numeric))
29
24
  lambda do
30
25
  @mock.random_call("1")
31
26
  end.should raise_error(MockExpectationError)
32
27
  end
33
28
 
34
29
  it "should reject non string" do
35
- @mock.should_receive(:random_call).with(:string)
30
+ @mock.should_receive(:random_call).with(an_instance_of(String))
36
31
  lambda do
37
32
  @mock.random_call(123)
38
33
  end.should raise_error(MockExpectationError)
39
34
  end
40
35
 
36
+ it "should reject goose when expecting a duck" do
37
+ @mock.should_receive(:random_call).with(duck_type(:abs, :div))
38
+ lambda { @mock.random_call("I don't respond to :abs or :div") }.should raise_error(MockExpectationError)
39
+ end
40
+
41
41
  it "should fail if regexp does not match submitted string" do
42
42
  @mock.should_receive(:random_call).with(/bcd/)
43
43
  lambda { @mock.random_call("abc") }.should raise_error(MockExpectationError)
@@ -68,6 +68,47 @@ module Spec
68
68
  @mock.msg(37)
69
69
  end.should raise_error(MockExpectationError, "Mock 'test mock' expected :msg with (equal 3) but received it with (37)")
70
70
  end
71
+
72
+ it "should fail no_args with one arg" do
73
+ lambda do
74
+ @mock.should_receive(:msg).with(no_args)
75
+ @mock.msg(37)
76
+ end.should raise_error(MockExpectationError, "Mock 'test mock' expected :msg with (no args) but received it with (37)")
77
+ end
78
+ end
79
+
80
+ describe "failing deprecated MockArgumentConstraints" do
81
+ before(:each) do
82
+ @mock = mock("test mock")
83
+ @reporter = Mock.new("reporter", :null_object => true)
84
+ end
85
+
86
+ after(:each) do
87
+ @mock.rspec_reset
88
+ end
89
+
90
+ it "should reject non boolean" do
91
+ @mock.should_receive(:random_call).with(:boolean)
92
+ lambda do
93
+ @mock.random_call("false")
94
+ end.should raise_error(MockExpectationError)
95
+ end
96
+
97
+ it "should reject non numeric" do
98
+ @mock.should_receive(:random_call).with(:numeric)
99
+ lambda do
100
+ @mock.random_call("1")
101
+ end.should raise_error(MockExpectationError)
102
+ end
103
+
104
+ it "should reject non string" do
105
+ @mock.should_receive(:random_call).with(:string)
106
+ lambda do
107
+ @mock.random_call(123)
108
+ end.should raise_error(MockExpectationError)
109
+ end
110
+
111
+
71
112
  end
72
113
  end
73
114
  end
@@ -180,7 +180,7 @@ module Spec
180
180
  end
181
181
 
182
182
  it "should ignore args on any args" do
183
- @mock.should_receive(:something).at_least(:once).with(:any_args)
183
+ @mock.should_receive(:something).at_least(:once).with(any_args)
184
184
  @mock.something
185
185
  @mock.something 1
186
186
  @mock.something "a", 2
@@ -189,7 +189,7 @@ module Spec
189
189
  end
190
190
 
191
191
  it "should fail on no args if any args received" do
192
- @mock.should_receive(:something).with(:no_args)
192
+ @mock.should_receive(:something).with(no_args())
193
193
  begin
194
194
  @mock.something 1
195
195
  rescue MockExpectationError => e
@@ -207,7 +207,7 @@ module Spec
207
207
  end
208
208
 
209
209
  it "should yield 0 args to blocks that take a variable number of arguments" do
210
- @mock.should_receive(:yield_back).with(:no_args).once.and_yield
210
+ @mock.should_receive(:yield_back).with(no_args()).once.and_yield
211
211
  a = nil
212
212
  @mock.yield_back {|*a|}
213
213
  a.should == []
@@ -215,7 +215,7 @@ module Spec
215
215
  end
216
216
 
217
217
  it "should yield one arg to blocks that take a variable number of arguments" do
218
- @mock.should_receive(:yield_back).with(:no_args).once.and_yield(99)
218
+ @mock.should_receive(:yield_back).with(no_args()).once.and_yield(99)
219
219
  a = nil
220
220
  @mock.yield_back {|*a|}
221
221
  a.should == [99]
@@ -223,7 +223,7 @@ module Spec
223
223
  end
224
224
 
225
225
  it "should yield many args to blocks that take a variable number of arguments" do
226
- @mock.should_receive(:yield_back).with(:no_args).once.and_yield(99, 27, "go")
226
+ @mock.should_receive(:yield_back).with(no_args()).once.and_yield(99, 27, "go")
227
227
  a = nil
228
228
  @mock.yield_back {|*a|}
229
229
  a.should == [99, 27, "go"]
@@ -231,7 +231,7 @@ module Spec
231
231
  end
232
232
 
233
233
  it "should yield single value" do
234
- @mock.should_receive(:yield_back).with(:no_args).once.and_yield(99)
234
+ @mock.should_receive(:yield_back).with(no_args()).once.and_yield(99)
235
235
  a = nil
236
236
  @mock.yield_back {|a|}
237
237
  a.should == 99
@@ -239,7 +239,7 @@ module Spec
239
239
  end
240
240
 
241
241
  it "should yield two values" do
242
- @mock.should_receive(:yield_back).with(:no_args).once.and_yield('wha', 'zup')
242
+ @mock.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
243
243
  a, b = nil
244
244
  @mock.yield_back {|a,b|}
245
245
  a.should == 'wha'
@@ -248,7 +248,7 @@ module Spec
248
248
  end
249
249
 
250
250
  it "should fail when calling yielding method with wrong arity" do
251
- @mock.should_receive(:yield_back).with(:no_args).once.and_yield('wha', 'zup')
251
+ @mock.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
252
252
  begin
253
253
  @mock.yield_back {|a|}
254
254
  rescue MockExpectationError => e
@@ -257,7 +257,7 @@ module Spec
257
257
  end
258
258
 
259
259
  it "should fail when calling yielding method without block" do
260
- @mock.should_receive(:yield_back).with(:no_args).once.and_yield('wha', 'zup')
260
+ @mock.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
261
261
  begin
262
262
  @mock.yield_back
263
263
  rescue MockExpectationError => e
@@ -266,7 +266,7 @@ module Spec
266
266
  end
267
267
 
268
268
  it "should be able to mock send" do
269
- @mock.should_receive(:send).with(:any_args)
269
+ @mock.should_receive(:send).with(any_args)
270
270
  @mock.send 'hi'
271
271
  @mock.rspec_verify
272
272
  end
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  module Spec
4
4
  module Mocks
5
- describe "a mock, in handling arguments" do
5
+ describe "mock argument constraints", :shared => true do
6
6
  before(:each) do
7
7
  @mock = Mock.new("test mock")
8
8
  end
@@ -10,6 +10,10 @@ module Spec
10
10
  after(:each) do
11
11
  @mock.rspec_verify
12
12
  end
13
+ end
14
+
15
+ describe Methods, "handling argument constraints with DEPRECATED symbols" do
16
+ it_should_behave_like "mock argument constraints"
13
17
 
14
18
  it "should accept true as boolean" do
15
19
  @mock.should_receive(:random_call).with(:boolean)
@@ -36,26 +40,78 @@ module Spec
36
40
  @mock.random_call("a", "whatever", "c")
37
41
  end
38
42
 
43
+ it "should match string" do
44
+ @mock.should_receive(:random_call).with(:string)
45
+ @mock.random_call("a string")
46
+ end
47
+
48
+ it "should match no args against any_args" do
49
+ @mock.should_receive(:random_call).with(:any_args)
50
+ @mock.random_call("a string")
51
+ end
52
+ end
53
+
54
+ describe Methods, "handling argument constraints" do
55
+ it_should_behave_like "mock argument constraints"
56
+
57
+ it "should accept true as boolean()" do
58
+ @mock.should_receive(:random_call).with(boolean())
59
+ @mock.random_call(true)
60
+ end
61
+
62
+ it "should accept false as boolean()" do
63
+ @mock.should_receive(:random_call).with(boolean())
64
+ @mock.random_call(false)
65
+ end
66
+
67
+ it "should accept fixnum as an_instance_of(Numeric)" do
68
+ @mock.should_receive(:random_call).with(an_instance_of(Numeric))
69
+ @mock.random_call(1)
70
+ end
71
+
72
+ it "should accept float as an_instance_of(Numeric)" do
73
+ @mock.should_receive(:random_call).with(an_instance_of(Numeric))
74
+ @mock.random_call(1.5)
75
+ end
76
+
77
+ it "should accept string as anything()" do
78
+ @mock.should_receive(:random_call).with("a", anything(), "c")
79
+ @mock.random_call("a", "whatever", "c")
80
+ end
81
+
39
82
  it "should match duck type with one method" do
40
- @mock.should_receive(:random_call).with(DuckTypeArgConstraint.new(:length))
83
+ @mock.should_receive(:random_call).with(duck_type(:length))
41
84
  @mock.random_call([])
42
85
  end
43
86
 
44
87
  it "should match duck type with two methods" do
45
- @mock.should_receive(:random_call).with(DuckTypeArgConstraint.new(:abs, :div))
88
+ @mock.should_receive(:random_call).with(duck_type(:abs, :div))
46
89
  @mock.random_call(1)
47
90
  end
91
+
92
+ it "should match no args against any_args()" do
93
+ @mock.should_receive(:random_call).with(any_args)
94
+ @mock.random_call()
95
+ end
96
+
97
+ it "should match one arg against any_args()" do
98
+ @mock.should_receive(:random_call).with(any_args)
99
+ @mock.random_call("a string")
100
+ end
101
+
102
+ it "should match no args against no_args()" do
103
+ @mock.should_receive(:random_call).with(no_args)
104
+ @mock.random_call()
105
+ end
106
+ end
107
+
108
+ describe Methods, "handling non-constraint arguments" do
48
109
 
49
- it "should match non special symbol" do
110
+ it "should match non special symbol (can be removed when deprecated symbols are removed)" do
50
111
  @mock.should_receive(:random_call).with(:some_symbol)
51
112
  @mock.random_call(:some_symbol)
52
113
  end
53
114
 
54
- it "should match string" do
55
- @mock.should_receive(:random_call).with(:string)
56
- @mock.random_call("a string")
57
- end
58
-
59
115
  it "should match string against regexp" do
60
116
  @mock.should_receive(:random_call).with(/bcd/)
61
117
  @mock.random_call("abcde")
@@ -113,7 +113,7 @@ module Spec
113
113
 
114
114
  it "sets Expectations differ when differ_class is set" do
115
115
  @options.differ_class = Spec::Expectations::Differs::Default
116
- Spec::Expectations.should_receive(:differ=).with(:anything).and_return do |arg|
116
+ Spec::Expectations.should_receive(:differ=).with(anything()).and_return do |arg|
117
117
  arg.class.should == Spec::Expectations::Differs::Default
118
118
  end
119
119
  @options.create_behaviour_runner
@@ -30,7 +30,7 @@ module Spec
30
30
  @formatter.should_receive(:example_started).exactly(3).times
31
31
  @formatter.should_receive(:example_passed).exactly(3).times
32
32
  @formatter.should_receive(:start_dump)
33
- @formatter.should_receive(:dump_summary).with(:anything, 3, 0, 0)
33
+ @formatter.should_receive(:dump_summary).with(anything(), 3, 0, 0)
34
34
  @reporter.add_behaviour("behaviour")
35
35
  @reporter.example_started("spec 1")
36
36
  @reporter.example_finished("spec 1")
@@ -51,7 +51,7 @@ module Spec
51
51
  @formatter.should_receive(:example_failed).with("example", 2, failure)
52
52
  @formatter.should_receive(:dump_failure).exactly(2).times
53
53
  @formatter.should_receive(:start_dump)
54
- @formatter.should_receive(:dump_summary).with(:anything, 4, 2, 0)
54
+ @formatter.should_receive(:dump_summary).with(anything(), 4, 2, 0)
55
55
  @backtrace_tweaker.should_receive(:tweak_backtrace).twice
56
56
  @reporter.add_behaviour("behaviour")
57
57
  @reporter.example_finished("example")
@@ -64,7 +64,7 @@ module Spec
64
64
 
65
65
  it "should push stats to formatter even with no data" do
66
66
  @formatter.should_receive(:start_dump)
67
- @formatter.should_receive(:dump_summary).with(:anything, 0, 0, 0)
67
+ @formatter.should_receive(:dump_summary).with(anything(), 0, 0, 0)
68
68
  @reporter.dump
69
69
  end
70
70
 
@@ -98,7 +98,7 @@ module Spec
98
98
  it "should account for passing example in stats" do
99
99
  @formatter.should_receive(:example_passed)
100
100
  @formatter.should_receive(:start_dump)
101
- @formatter.should_receive(:dump_summary).with(:anything, 1, 0, 0)
101
+ @formatter.should_receive(:dump_summary).with(anything(), 1, 0, 0)
102
102
  @reporter.example_finished("example")
103
103
  @reporter.dump
104
104
  end
@@ -123,8 +123,8 @@ module Spec
123
123
  @formatter.should_receive(:add_behaviour)
124
124
  @formatter.should_receive(:example_failed).with("example", 1, failure)
125
125
  @formatter.should_receive(:start_dump)
126
- @formatter.should_receive(:dump_failure).with(1, :anything)
127
- @formatter.should_receive(:dump_summary).with(:anything, 1, 1, 0)
126
+ @formatter.should_receive(:dump_failure).with(1, anything())
127
+ @formatter.should_receive(:dump_summary).with(anything(), 1, 1, 0)
128
128
  @reporter.add_behaviour("behaviour")
129
129
  @reporter.example_finished("example", RuntimeError.new)
130
130
  @reporter.dump
@@ -144,7 +144,7 @@ module Spec
144
144
  it "should account for not implemented example in stats" do
145
145
  @formatter.should_receive(:example_not_implemented)
146
146
  @formatter.should_receive(:start_dump)
147
- @formatter.should_receive(:dump_summary).with(:anything, 1, 0, 1)
147
+ @formatter.should_receive(:dump_summary).with(anything(), 1, 0, 1)
148
148
  @reporter.example_finished("example", nil, nil, true)
149
149
  @reporter.dump
150
150
  end
@@ -6,6 +6,7 @@ lib_path = File.expand_path("#{dir}/../lib")
6
6
  $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
7
7
 
8
8
  require 'spec'
9
+ require 'spec/mocks'
9
10
  require 'hpricot'
10
11
  spec_classes_path = File.expand_path("#{dir}/../spec/spec/spec_classes")
11
12
  require spec_classes_path unless $LOAD_PATH.include?(spec_classes_path)
metadata CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: rspec
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.3
7
- date: 2007-05-25 00:00:00 -05:00
8
- summary: RSpec-1.0.3 (r2035) - BDD for Ruby http://rspec.rubyforge.org/
6
+ version: 1.0.4
7
+ date: 2007-05-29 00:00:00 -04:00
8
+ summary: RSpec-1.0.4 (r2054) - BDD for Ruby http://rspec.rubyforge.org/
9
9
  require_paths:
10
10
  - lib
11
11
  email: rspec-devel@rubyforge.org
@@ -142,6 +142,7 @@ files:
142
142
  - spec/spec/matchers/include_spec.rb
143
143
  - spec/spec/matchers/match_spec.rb
144
144
  - spec/spec/matchers/matcher_methods_spec.rb
145
+ - spec/spec/matchers/mock_constraint_matchers_spec.rb
145
146
  - spec/spec/matchers/operator_matcher_spec.rb
146
147
  - spec/spec/matchers/raise_error_spec.rb
147
148
  - spec/spec/matchers/respond_to_spec.rb