dchelimsky-rspec 1.1.11.7 → 1.1.12

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 (79) hide show
  1. data/History.txt +1 -1
  2. data/features/support/helpers/story_helper.rb +0 -3
  3. data/lib/spec/example/example_group_methods.rb +1 -1
  4. data/lib/spec/matchers.rb +1 -1
  5. data/lib/spec/mocks.rb +3 -3
  6. data/lib/spec/mocks/argument_expectation.rb +14 -14
  7. data/lib/spec/mocks/framework.rb +1 -1
  8. data/lib/spec/mocks/message_expectation.rb +1 -1
  9. data/lib/spec/mocks/mock.rb +3 -4
  10. data/lib/spec/mocks/spec_methods.rb +10 -1
  11. data/lib/spec/version.rb +2 -2
  12. data/rspec.gemspec +3 -3
  13. data/spec/spec/mocks/hash_including_matcher_spec.rb +4 -4
  14. data/spec/spec/mocks/hash_not_including_matcher_spec.rb +3 -3
  15. data/spec/spec/mocks/mock_spec.rb +25 -0
  16. data/spec/spec/runner/reporter_spec.rb +1 -1
  17. data/spec/spec_helper.rb +0 -1
  18. metadata +3 -3
  19. data/lib/spec/mocks/argument_constraints.rb +0 -237
  20. data/lib/spec/runner/formatter/story/html_formatter.rb +0 -174
  21. data/lib/spec/runner/formatter/story/plain_text_formatter.rb +0 -194
  22. data/lib/spec/runner/formatter/story/progress_bar_formatter.rb +0 -42
  23. data/lib/spec/story.rb +0 -10
  24. data/lib/spec/story/extensions.rb +0 -3
  25. data/lib/spec/story/extensions/main.rb +0 -86
  26. data/lib/spec/story/extensions/regexp.rb +0 -9
  27. data/lib/spec/story/extensions/string.rb +0 -9
  28. data/lib/spec/story/given_scenario.rb +0 -14
  29. data/lib/spec/story/runner.rb +0 -57
  30. data/lib/spec/story/runner/plain_text_story_runner.rb +0 -48
  31. data/lib/spec/story/runner/scenario_collector.rb +0 -18
  32. data/lib/spec/story/runner/scenario_runner.rb +0 -54
  33. data/lib/spec/story/runner/story_mediator.rb +0 -137
  34. data/lib/spec/story/runner/story_parser.rb +0 -247
  35. data/lib/spec/story/runner/story_runner.rb +0 -74
  36. data/lib/spec/story/scenario.rb +0 -14
  37. data/lib/spec/story/step.rb +0 -70
  38. data/lib/spec/story/step_group.rb +0 -89
  39. data/lib/spec/story/step_mother.rb +0 -38
  40. data/lib/spec/story/story.rb +0 -39
  41. data/lib/spec/story/world.rb +0 -124
  42. data/spec/spec/matchers/mock_constraint_matchers_spec.rb +0 -24
  43. data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +0 -95
  44. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +0 -145
  45. data/spec/spec/runner/formatter/story/html_formatter_spec.rb +0 -135
  46. data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +0 -600
  47. data/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb +0 -82
  48. data/spec/spec/story/builders.rb +0 -46
  49. data/spec/spec/story/extensions/main_spec.rb +0 -161
  50. data/spec/spec/story/extensions_spec.rb +0 -14
  51. data/spec/spec/story/given_scenario_spec.rb +0 -27
  52. data/spec/spec/story/runner/plain_text_story_runner_spec.rb +0 -90
  53. data/spec/spec/story/runner/scenario_collector_spec.rb +0 -27
  54. data/spec/spec/story/runner/scenario_runner_spec.rb +0 -214
  55. data/spec/spec/story/runner/story_mediator_spec.rb +0 -143
  56. data/spec/spec/story/runner/story_parser_spec.rb +0 -401
  57. data/spec/spec/story/runner/story_runner_spec.rb +0 -294
  58. data/spec/spec/story/runner_spec.rb +0 -93
  59. data/spec/spec/story/scenario_spec.rb +0 -18
  60. data/spec/spec/story/step_group_spec.rb +0 -157
  61. data/spec/spec/story/step_mother_spec.rb +0 -84
  62. data/spec/spec/story/step_spec.rb +0 -272
  63. data/spec/spec/story/story_helper.rb +0 -2
  64. data/spec/spec/story/story_spec.rb +0 -84
  65. data/spec/spec/story/world_spec.rb +0 -423
  66. data/story_server/prototype/javascripts/builder.js +0 -136
  67. data/story_server/prototype/javascripts/controls.js +0 -972
  68. data/story_server/prototype/javascripts/dragdrop.js +0 -976
  69. data/story_server/prototype/javascripts/effects.js +0 -1117
  70. data/story_server/prototype/javascripts/prototype.js +0 -4140
  71. data/story_server/prototype/javascripts/rspec.js +0 -149
  72. data/story_server/prototype/javascripts/scriptaculous.js +0 -58
  73. data/story_server/prototype/javascripts/slider.js +0 -276
  74. data/story_server/prototype/javascripts/sound.js +0 -55
  75. data/story_server/prototype/javascripts/unittest.js +0 -568
  76. data/story_server/prototype/lib/server.rb +0 -24
  77. data/story_server/prototype/stories.html +0 -176
  78. data/story_server/prototype/stylesheets/rspec.css +0 -136
  79. data/story_server/prototype/stylesheets/test.css +0 -90
data/History.txt CHANGED
@@ -1,4 +1,4 @@
1
- === Maintenance
1
+ === Version 1.1.12 / 2009-01-11
2
2
 
3
3
  WARNING: there was a stub/mock bug in 1.1.11 that allowed a structure that was
4
4
  not intended:
@@ -1,4 +1,3 @@
1
- require 'spec/story'
2
1
  require File.dirname(__FILE__) + '/../../../spec/ruby_forker'
3
2
 
4
3
  module StoryHelper
@@ -11,6 +10,4 @@ module StoryHelper
11
10
  def cmdline(args, stderr)
12
11
  ruby("#{File.dirname(__FILE__) + '/../../resources/helpers/cmdline.rb'} #{args}", stderr)
13
12
  end
14
-
15
- Spec::Story::World.__send__ :include, self
16
13
  end
@@ -118,7 +118,7 @@ WARNING
118
118
  # exist (for state expectations)
119
119
  # File.should exist("path/to/file")
120
120
  #
121
- # an_instance_of (for mock argument constraints)
121
+ # an_instance_of (for mock argument matchers)
122
122
  # mock.should_receive(:message).with(an_instance_of(String))
123
123
  #
124
124
  # == Examples
data/lib/spec/matchers.rb CHANGED
@@ -31,7 +31,7 @@ module Spec
31
31
  # description #optional
32
32
  #
33
33
  # See Spec::Expectations to learn how to use these as Expectation Matchers.
34
- # See Spec::Mocks to learn how to use them as Mock Argument Constraints.
34
+ # See Spec::Mocks to learn how to use them as Mock Argument Matchers.
35
35
  #
36
36
  # == Predicates
37
37
  #
data/lib/spec/mocks.rb CHANGED
@@ -105,11 +105,11 @@ module Spec
105
105
  # my_mock.should_receive(:sym).with(*args)
106
106
  # my_mock.should_not_receive(:sym).with(*args)
107
107
  #
108
- # == Argument Constraints using Expression Matchers
108
+ # == Argument Matchers
109
109
  #
110
110
  # Arguments that are passed to #with are compared with actual arguments received
111
111
  # using == by default. In cases in which you want to specify things about the arguments
112
- # rather than the arguments themselves, you can use any of the Expression Matchers.
112
+ # rather than the arguments themselves, you can use any of RSpec's Expression Matchers.
113
113
  # They don't all make syntactic sense (they were primarily designed for use with
114
114
  # Spec::Expectations), but you are free to create your own custom Spec::Matchers.
115
115
  #
@@ -120,7 +120,7 @@ module Spec
120
120
  #
121
121
  # my_mock.should_receive(:sym).with(no_args())
122
122
  # my_mock.should_receive(:sym).with(any_args())
123
- # my_mock.should_receive(:sym).with(1, an_instance_of(Numeric), "b") #2nd argument can any type of Numeric
123
+ # my_mock.should_receive(:sym).with(1, kind_of(Numeric), "b") #2nd argument can any kind of Numeric
124
124
  # my_mock.should_receive(:sym).with(1, boolean(), "b") #2nd argument can true or false
125
125
  # my_mock.should_receive(:sym).with(1, /abc/, "b") #2nd argument can be any String matching the submitted Regexp
126
126
  # my_mock.should_receive(:sym).with(1, anything(), "b") #2nd argument can be anything at all
@@ -6,21 +6,21 @@ module Spec
6
6
 
7
7
  def initialize(args, &block)
8
8
  @args = args
9
- @constraints_block = block
9
+ @matchers_block = block
10
10
 
11
- if ArgumentConstraints::AnyArgsConstraint === args.first
11
+ if ArgumentMatchers::AnyArgsMatcher === args.first
12
12
  @match_any_args = true
13
- elsif ArgumentConstraints::NoArgsConstraint === args.first
14
- @constraints = []
13
+ elsif ArgumentMatchers::NoArgsMatcher === args.first
14
+ @matchers = []
15
15
  else
16
- @constraints = args.collect {|arg| constraint_for(arg)}
16
+ @matchers = args.collect {|arg| matcher_for(arg)}
17
17
  end
18
18
  end
19
19
 
20
- def constraint_for(arg)
21
- return ArgumentConstraints::MatcherConstraint.new(arg) if is_matcher?(arg)
22
- return ArgumentConstraints::RegexpConstraint.new(arg) if arg.is_a?(Regexp)
23
- return ArgumentConstraints::EqualityProxy.new(arg)
20
+ def matcher_for(arg)
21
+ return ArgumentMatchers::MatcherMatcher.new(arg) if is_matcher?(arg)
22
+ return ArgumentMatchers::RegexpMatcher.new(arg) if arg.is_a?(Regexp)
23
+ return ArgumentMatchers::EqualityProxy.new(arg)
24
24
  end
25
25
 
26
26
  def is_matcher?(obj)
@@ -28,15 +28,15 @@ module Spec
28
28
  end
29
29
 
30
30
  def args_match?(given_args)
31
- match_any_args? || constraints_block_matches?(given_args) || constraints_match?(given_args)
31
+ match_any_args? || matchers_block_matches?(given_args) || matchers_match?(given_args)
32
32
  end
33
33
 
34
- def constraints_block_matches?(given_args)
35
- @constraints_block ? @constraints_block.call(*given_args) : nil
34
+ def matchers_block_matches?(given_args)
35
+ @matchers_block ? @matchers_block.call(*given_args) : nil
36
36
  end
37
37
 
38
- def constraints_match?(given_args)
39
- @constraints == given_args
38
+ def matchers_match?(given_args)
39
+ @matchers == given_args
40
40
  end
41
41
 
42
42
  def match_any_args?
@@ -3,7 +3,7 @@
3
3
  # object in the system.
4
4
 
5
5
  require 'spec/mocks/methods'
6
- require 'spec/mocks/argument_constraints'
6
+ require 'spec/mocks/argument_matchers'
7
7
  require 'spec/mocks/spec_methods'
8
8
  require 'spec/mocks/proxy'
9
9
  require 'spec/mocks/mock'
@@ -17,7 +17,7 @@ module Spec
17
17
  @return_block = nil
18
18
  @actual_received_count = 0
19
19
  @expected_received_count = expected_received_count
20
- @args_expectation = ArgumentExpectation.new([ArgumentConstraints::AnyArgsConstraint.new])
20
+ @args_expectation = ArgumentExpectation.new([ArgumentMatchers::AnyArgsMatcher.new])
21
21
  @consecutive = false
22
22
  @exception_to_raise = nil
23
23
  @symbol_to_throw = nil
@@ -14,10 +14,9 @@ module Spec
14
14
  end
15
15
 
16
16
  # This allows for comparing the mock to other objects that proxy such as
17
- # ActiveRecords belongs_to proxy objects By making the other object run
18
- # the comparison, we're sure the call gets delegated to the proxy target
19
- # This is an unfortunate side effect from ActiveRecord, but this should
20
- # be safe unless the RHS redefines == in a nonsensical manner
17
+ # ActiveRecords belongs_to proxy objects. By making the other object run
18
+ # the comparison, we're sure the call gets delegated to the proxy
19
+ # target.
21
20
  def ==(other)
22
21
  other == __mock_proxy
23
22
  end
@@ -1,7 +1,7 @@
1
1
  module Spec
2
2
  module Mocks
3
3
  module ExampleMethods
4
- include Spec::Mocks::ArgumentConstraints
4
+ include Spec::Mocks::ArgumentMatchers
5
5
 
6
6
  # Shortcut for creating an instance of Spec::Mocks::Mock.
7
7
  #
@@ -26,10 +26,19 @@ module Spec
26
26
 
27
27
  alias :stub :mock
28
28
 
29
+ # DEPRECATED - use mock('name').as_null_object instead
30
+ #
29
31
  # Shortcut for creating a mock object that will return itself in response
30
32
  # to any message it receives that it hasn't been explicitly instructed
31
33
  # to respond to.
32
34
  def stub_everything(name = 'stub')
35
+ Kernel.warn(<<-WARNING)
36
+
37
+ DEPRECATION: stub_everything('#{name}') is deprecated and will be removed
38
+ from a future version of rspec. Please use mock('#{name}').as_null_object
39
+ or stub('#{name}').as_null_object instead.
40
+
41
+ WARNING
33
42
  mock(name, :null_object => true)
34
43
  end
35
44
 
data/lib/spec/version.rb CHANGED
@@ -3,8 +3,8 @@ module Spec
3
3
  unless defined? MAJOR
4
4
  MAJOR = 1
5
5
  MINOR = 1
6
- TINY = 11
7
- MINESCULE = 7
6
+ TINY = 12
7
+ MINESCULE = nil
8
8
 
9
9
 
10
10
  STRING = [MAJOR, MINOR, TINY, MINESCULE].compact.join('.')
data/rspec.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rspec}
5
- s.version = "1.1.11.7"
5
+ s.version = "1.1.12"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["RSpec Development Team"]
9
- s.date = %q{2009-01-09}
9
+ s.date = %q{2009-01-11}
10
10
  s.description = %q{Behaviour Driven Development for Ruby.}
11
11
  s.email = ["rspec-devel@rubyforge.org"]
12
12
  s.executables = ["autospec", "spec"]
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
  s.rubyforge_project = %q{rspec}
20
20
  s.rubygems_version = %q{1.3.1}
21
- s.summary = %q{rspec 1.1.11.7}
21
+ s.summary = %q{rspec 1.1.12}
22
22
 
23
23
  if s.respond_to? :specification_version then
24
24
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -2,11 +2,11 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  module Spec
4
4
  module Mocks
5
- module ArgumentConstraints
6
- describe HashIncludingConstraint do
5
+ module ArgumentMatchers
6
+ describe HashIncludingMatcher do
7
7
 
8
8
  it "should describe itself properly" do
9
- HashIncludingConstraint.new(:a => 1).description.should == "hash_including(:a=>1)"
9
+ HashIncludingMatcher.new(:a => 1).description.should == "hash_including(:a=>1)"
10
10
  end
11
11
 
12
12
  describe "passing" do
@@ -18,7 +18,7 @@ module Spec
18
18
  hash_including(:a => 1).should == {:a => 1, :b => 2}
19
19
  end
20
20
 
21
- describe "when matching against other constraints" do
21
+ describe "when matching against other matchers" do
22
22
  it "should match an int against anything()" do
23
23
  hash_including(:a => anything, :b => 2).should == {:a => 1, :b => 2}
24
24
  end
@@ -2,11 +2,11 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  module Spec
4
4
  module Mocks
5
- module ArgumentConstraints
6
- describe HashNotIncludingConstraint do
5
+ module ArgumentMatchers
6
+ describe HashNotIncludingMatcher do
7
7
 
8
8
  it "should describe itself properly" do
9
- HashNotIncludingConstraint.new(:a => 5).description.should == "hash_not_including(:a=>5)"
9
+ HashNotIncludingMatcher.new(:a => 5).description.should == "hash_not_including(:a=>5)"
10
10
  end
11
11
 
12
12
  describe "passing" do
@@ -11,6 +11,21 @@ module Spec
11
11
  @mock.rspec_reset
12
12
  end
13
13
 
14
+ describe "deprecated #stub_everything method" do
15
+ before(:each) do
16
+ Kernel.stub!(:warn)
17
+ end
18
+
19
+ it "creates a mock that behaves as a null object" do
20
+ stub_everything.should be_null_object
21
+ end
22
+
23
+ it "provides deprecation warning" do
24
+ Kernel.should_receive(:warn).with(/DEPRECATION: stub_everything.* is deprecated./)
25
+ stub_everything
26
+ end
27
+ end
28
+
14
29
  it "should report line number of expectation of unreceived message" do
15
30
  expected_error_line = __LINE__; @mock.should_receive(:wont_happen).with("x", 3)
16
31
  begin
@@ -550,5 +565,15 @@ module Spec
550
565
  valid_html_str.should_not include('<')
551
566
  end
552
567
  end
568
+
569
+ describe "==" do
570
+ it "sends '== self' to the comparison object" do
571
+ first = mock('first')
572
+ second = mock('second')
573
+
574
+ first.should_receive(:==).with(second)
575
+ second == first
576
+ end
577
+ end
553
578
  end
554
579
  end
@@ -17,7 +17,7 @@ module Spec
17
17
  end
18
18
 
19
19
  def failure
20
- Mocks::ArgumentConstraints::DuckTypeConstraint.new(:header, :exception)
20
+ Mocks::ArgumentMatchers::DuckTypeMatcher.new(:header, :exception)
21
21
  end
22
22
 
23
23
  def create_example_group(description_text)
data/spec/spec_helper.rb CHANGED
@@ -7,7 +7,6 @@ $_spec_spec = true # Prevents Kernel.exit in various places
7
7
 
8
8
  require 'spec'
9
9
  require 'spec/mocks'
10
- require 'spec/story'
11
10
  spec_classes_path = File.expand_path("#{dir}/../spec/spec/spec_classes")
12
11
  require spec_classes_path unless $LOAD_PATH.include?(spec_classes_path)
13
12
  require File.dirname(__FILE__) + '/../lib/spec/expectations/differs/default'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dchelimsky-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.11.7
4
+ version: 1.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - RSpec Development Team
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-09 00:00:00 -08:00
12
+ date: 2009-01-11 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -442,6 +442,6 @@ rubyforge_project: rspec
442
442
  rubygems_version: 1.2.0
443
443
  signing_key:
444
444
  specification_version: 2
445
- summary: rspec 1.1.11.7
445
+ summary: rspec 1.1.12
446
446
  test_files: []
447
447
 
@@ -1,237 +0,0 @@
1
- module Spec
2
- module Mocks
3
-
4
- # ArgumentConstraints are messages that you can include in message
5
- # expectations to match arguments against a broader check than simple
6
- # equality.
7
- #
8
- # With the exception of any_args() and no_args(), the constraints
9
- # are all positional - they match against the arg in the given position.
10
- module ArgumentConstraints
11
-
12
- class AnyArgsConstraint
13
- def description
14
- "any args"
15
- end
16
- end
17
-
18
- class AnyArgConstraint
19
- def initialize(ignore)
20
- end
21
-
22
- def ==(other)
23
- true
24
- end
25
- end
26
-
27
- class NoArgsConstraint
28
- def description
29
- "no args"
30
- end
31
-
32
- def ==(args)
33
- args == []
34
- end
35
- end
36
-
37
- class RegexpConstraint
38
- def initialize(regexp)
39
- @regexp = regexp
40
- end
41
-
42
- def ==(value)
43
- return value =~ @regexp unless value.is_a?(Regexp)
44
- value == @regexp
45
- end
46
- end
47
-
48
- class BooleanConstraint
49
- def initialize(ignore)
50
- end
51
-
52
- def ==(value)
53
- TrueClass === value || FalseClass === value
54
- end
55
- end
56
-
57
- class HashIncludingConstraint
58
- def initialize(expected)
59
- @expected = expected
60
- end
61
-
62
- def ==(actual)
63
- @expected.each do | key, value |
64
- return false unless actual.has_key?(key) && value == actual[key]
65
- end
66
- true
67
- rescue NoMethodError => ex
68
- return false
69
- end
70
-
71
- def description
72
- "hash_including(#{@expected.inspect.sub(/^\{/,"").sub(/\}$/,"")})"
73
- end
74
- end
75
-
76
- class HashNotIncludingConstraint
77
- def initialize(expected)
78
- @expected = expected
79
- end
80
-
81
- def ==(actual)
82
- @expected.each do | key, value |
83
- return false if actual.has_key?(key) && value == actual[key]
84
- end
85
- true
86
- rescue NoMethodError => ex
87
- return false
88
- end
89
-
90
- def description
91
- "hash_not_including(#{@expected.inspect.sub(/^\{/,"").sub(/\}$/,"")})"
92
- end
93
- end
94
-
95
- class DuckTypeConstraint
96
- def initialize(*methods_to_respond_to)
97
- @methods_to_respond_to = methods_to_respond_to
98
- end
99
-
100
- def ==(value)
101
- @methods_to_respond_to.all? { |sym| value.respond_to?(sym) }
102
- end
103
- end
104
-
105
- class MatcherConstraint
106
- def initialize(matcher)
107
- @matcher = matcher
108
- end
109
-
110
- def ==(value)
111
- @matcher.matches?(value)
112
- end
113
- end
114
-
115
- class EqualityProxy
116
- def initialize(given)
117
- @given = given
118
- end
119
-
120
- def ==(expected)
121
- @given == expected
122
- end
123
- end
124
-
125
- class InstanceOf
126
- def initialize(klass)
127
- @klass = klass
128
- end
129
-
130
- def ==(actual)
131
- actual.instance_of?(@klass)
132
- end
133
- end
134
-
135
- class KindOf
136
- def initialize(klass)
137
- @klass = klass
138
- end
139
-
140
- def ==(actual)
141
- actual.kind_of?(@klass)
142
- end
143
- end
144
-
145
- # :call-seq:
146
- # object.should_receive(:message).with(any_args())
147
- #
148
- # Passes if object receives :message with any args at all. This is
149
- # really a more explicit variation of object.should_receive(:message)
150
- def any_args
151
- AnyArgsConstraint.new
152
- end
153
-
154
- # :call-seq:
155
- # object.should_receive(:message).with(anything())
156
- #
157
- # Passes as long as there is an argument.
158
- def anything
159
- AnyArgConstraint.new(nil)
160
- end
161
-
162
- # :call-seq:
163
- # object.should_receive(:message).with(no_args)
164
- #
165
- # Passes if no arguments are passed along with the message
166
- def no_args
167
- NoArgsConstraint.new
168
- end
169
-
170
- # :call-seq:
171
- # object.should_receive(:message).with(duck_type(:hello))
172
- # object.should_receive(:message).with(duck_type(:hello, :goodbye))
173
- #
174
- # Passes if the argument responds to the specified messages.
175
- #
176
- # == Examples
177
- #
178
- # array = []
179
- # display = mock('display')
180
- # display.should_receive(:present_names).with(duck_type(:length, :each))
181
- # => passes
182
- def duck_type(*args)
183
- DuckTypeConstraint.new(*args)
184
- end
185
-
186
- # :call-seq:
187
- # object.should_receive(:message).with(boolean())
188
- #
189
- # Passes if the argument is boolean.
190
- def boolean
191
- BooleanConstraint.new(nil)
192
- end
193
-
194
- # :call-seq:
195
- # object.should_receive(:message).with(hash_including(:key => val))
196
- # object.should_receive(:message).with(hash_including(:key))
197
- # object.should_receive(:message).with(hash_including(:key, :key2 => val2))
198
- # Passes if the argument is a hash that includes the specified key(s) or key/value
199
- # pairs. If the hash includes other keys, it will still pass.
200
- def hash_including(*args)
201
- HashIncludingConstraint.new(anythingize_lonely_keys(*args))
202
- end
203
-
204
- # :call-seq:
205
- # object.should_receive(:message).with(hash_not_including(:key => val))
206
- # object.should_receive(:message).with(hash_not_including(:key))
207
- # object.should_receive(:message).with(hash_not_including(:key, :key2 => :val2))
208
- #
209
- # Passes if the argument is a hash that doesn't include the specified key(s) or key/value
210
- def hash_not_including(*args)
211
- HashNotIncludingConstraint.new(anythingize_lonely_keys(*args))
212
- end
213
-
214
- # Passes if arg.instance_of?(klass)
215
- def instance_of(klass)
216
- InstanceOf.new(klass)
217
- end
218
-
219
- alias_method :an_instance_of, :instance_of
220
-
221
- # Passes if arg.kind_of?(klass)
222
- def kind_of(klass)
223
- KindOf.new(klass)
224
- end
225
-
226
- alias_method :a_kind_of, :kind_of
227
-
228
- private
229
-
230
- def anythingize_lonely_keys(*args)
231
- hash = args.last.class == Hash ? args.delete_at(-1) : {}
232
- args.each { | arg | hash[arg] = anything }
233
- hash
234
- end
235
- end
236
- end
237
- end