mocha 0.13.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
data/RELEASE.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Release Notes
2
2
 
3
+ ## 0.13.1
4
+ * Fix #97 - `Mocha::ParameterMatchers#has_entry` does not work with an Array as the entry's value. Thanks to @ngokli.
5
+ * Allow deprecation `:debug` mode to be switched on from `MOCHA_OPTIONS` environment variable.
6
+
3
7
  ## 0.13.0
4
8
  * Major overhaul of MiniTest & Test::Unit integration. Mocha now integrates with later versions of the two test libraries using documented hooks rather than monkey-patching. This should mean that Mocha will integrate with new versions of either library without the need to release a new version of Mocha each time, which was clearly bad and unsustainable. Many thanks to @tenderlove, @zenspider & @kou for their help, suggestions & patience.
5
9
  * Temporarily deprecated `require 'mocha'`. Use `require 'mocha/setup'` instead. The plan is that eventually `require 'mocha'` will *not* automatically integrate with either of the two test libraries as it does at the moment, and you'll need to explicitly & separately trigger the integration. I think this will provide a lot more flexibility and will hopefully do away with the need for the `require: false` option in the `Gemfile` which has always confused people.
@@ -1,3 +1,5 @@
1
+ require 'mocha/debug'
2
+
1
3
  module Mocha
2
4
 
3
5
  class Deprecation
@@ -14,7 +16,7 @@ module Mocha
14
16
 
15
17
  end
16
18
 
17
- self.mode = :enabled
19
+ self.mode = Debug::OPTIONS['debug'] ? :debug : :enabled
18
20
  self.messages = []
19
21
 
20
22
  end
@@ -42,16 +42,25 @@ module Mocha
42
42
  # object.method_1('key_1' => 2, 'key_2' => 1)
43
43
  # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1
44
44
  def has_entry(*options)
45
- key, value = options.shift, options.shift
46
- if key.is_a?(Hash)
47
- case key.length
48
- when 0
49
- raise ArgumentError.new("Argument has no entries.")
50
- when 1
51
- key, value = key.to_a.flatten
45
+ case options.length
46
+ when 1
47
+ case options[0]
48
+ when Hash
49
+ case options[0].length
50
+ when 0
51
+ raise ArgumentError.new("Argument has no entries.")
52
+ when 1
53
+ key, value = options[0].first
54
+ else
55
+ raise ArgumentError.new("Argument has multiple entries. Use Mocha::ParameterMatchers#has_entries instead.")
56
+ end
52
57
  else
53
- raise ArgumentError.new("Argument has multiple entries. Use Mocha::ParameterMatchers#has_entries instead.")
58
+ raise ArgumentError.new("Argument is not a Hash.")
54
59
  end
60
+ when 2
61
+ key, value = options
62
+ else
63
+ raise ArgumentError.new("Too many arguments; use either a single argument (must be a Hash) or two arguments (a key and a value).")
55
64
  end
56
65
  HasEntry.new(key, value)
57
66
  end
@@ -1,3 +1,3 @@
1
1
  module Mocha
2
- VERSION = "0.13.0"
2
+ VERSION = "0.13.1"
3
3
  end
@@ -79,6 +79,13 @@ class HasEntryTest < Test::Unit::TestCase
79
79
  assert !matcher.matches?([object])
80
80
  end
81
81
 
82
+ def test_should_raise_argument_error_if_single_argument_is_not_a_hash
83
+ e = assert_raises(ArgumentError) do
84
+ has_entry(Array.new)
85
+ end
86
+ assert_equal "Argument is not a Hash.", e.message
87
+ end
88
+
82
89
  def test_should_raise_argument_error_if_no_entries_are_supplied
83
90
  e = assert_raises(ArgumentError) do
84
91
  has_entry({})
@@ -93,4 +100,30 @@ class HasEntryTest < Test::Unit::TestCase
93
100
  assert_equal "Argument has multiple entries. Use Mocha::ParameterMatchers#has_entries instead.", e.message
94
101
  end
95
102
 
103
+ def test_should_raise_argument_error_if_more_than_two_arguments_are_supplied
104
+ e = assert_raises(ArgumentError) do
105
+ has_entry(1, 2, 3)
106
+ end
107
+ assert_equal "Too many arguments; use either a single argument (must be a Hash) or two arguments (a key and a value).", e.message
108
+ end
109
+
110
+ def test_should_match_array_as_key
111
+ matcher = has_entry([:key_1, :key_2] => 'value_1')
112
+ assert matcher.matches?([{[:key_1, :key_2] => 'value_1', :key_3 => 'value_2'}])
113
+ end
114
+
115
+ def test_should_match_array_as_value
116
+ matcher = has_entry(:key_1 => ['value_1', 'value_2'])
117
+ assert matcher.matches?([{:key_1 => ['value_1', 'value_2']}])
118
+ end
119
+
120
+ def test_should_match_hash_as_value_and_key
121
+ matcher = has_entry({{:key_1 => 'value_1', :key_2 => 'value_2'} => {:key_3 => 'value_3', :key_4 => 'value_4'}})
122
+ assert matcher.matches?([{{:key_1 => 'value_1', :key_2 => 'value_2'} => {:key_3 => 'value_3', :key_4 => 'value_4'}, :key_5 => 'value_5'}])
123
+ end
124
+
125
+ def test_should_match_matcher_as_value_and_key
126
+ matcher = has_entry({has_entry(:key_1 => 'value_1') => has_entry(:key_3 => 'value_3')})
127
+ assert matcher.matches?([{{:key_1 => 'value_1', :key_2 => 'value_2'} => {:key_3 => 'value_3', :key_4 => 'value_4'}, :key_5 => 'value_5'}])
128
+ end
96
129
  end
metadata CHANGED
@@ -1,78 +1,105 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mocha
3
- version: !ruby/object:Gem::Version
4
- version: 0.13.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 41
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 13
9
+ - 1
10
+ version: 0.13.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - James Mead
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-11-11 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: metaclass
16
- requirement: &70267336106140 !ruby/object:Gem::Requirement
17
+
18
+ date: 2012-12-04 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
17
22
  none: false
18
- requirements:
23
+ requirements:
19
24
  - - ~>
20
- - !ruby/object:Gem::Version
25
+ - !ruby/object:Gem::Version
26
+ hash: 29
27
+ segments:
28
+ - 0
29
+ - 0
30
+ - 1
21
31
  version: 0.0.1
32
+ name: metaclass
22
33
  type: :runtime
23
34
  prerelease: false
24
- version_requirements: *70267336106140
25
- - !ruby/object:Gem::Dependency
26
- name: rake
27
- requirement: &70267336104820 !ruby/object:Gem::Requirement
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
28
38
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ name: rake
33
47
  type: :development
34
48
  prerelease: false
35
- version_requirements: *70267336104820
36
- - !ruby/object:Gem::Dependency
37
- name: introspection
38
- requirement: &70267336104360 !ruby/object:Gem::Requirement
49
+ requirement: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
39
52
  none: false
40
- requirements:
53
+ requirements:
41
54
  - - ~>
42
- - !ruby/object:Gem::Version
55
+ - !ruby/object:Gem::Version
56
+ hash: 29
57
+ segments:
58
+ - 0
59
+ - 0
60
+ - 1
43
61
  version: 0.0.1
62
+ name: introspection
44
63
  type: :development
45
64
  prerelease: false
46
- version_requirements: *70267336104360
47
- - !ruby/object:Gem::Dependency
48
- name: yard
49
- requirement: &70267336103960 !ruby/object:Gem::Requirement
65
+ requirement: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
50
68
  none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ name: yard
55
77
  type: :development
56
78
  prerelease: false
57
- version_requirements: *70267336103960
58
- - !ruby/object:Gem::Dependency
59
- name: redcarpet
60
- requirement: &70267336103420 !ruby/object:Gem::Requirement
79
+ requirement: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
61
82
  none: false
62
- requirements:
83
+ requirements:
63
84
  - - ~>
64
- - !ruby/object:Gem::Version
65
- version: '1'
85
+ - !ruby/object:Gem::Version
86
+ hash: 1
87
+ segments:
88
+ - 1
89
+ version: "1"
90
+ name: redcarpet
66
91
  type: :development
67
92
  prerelease: false
68
- version_requirements: *70267336103420
69
- description: Mocking and stubbing library with JMock/SchMock syntax, which allows
70
- mocking and stubbing of methods on real (non-mock) classes.
93
+ requirement: *id005
94
+ description: Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.
71
95
  email: mocha-developer@googlegroups.com
72
96
  executables: []
97
+
73
98
  extensions: []
99
+
74
100
  extra_rdoc_files: []
75
- files:
101
+
102
+ files:
76
103
  - .gemtest
77
104
  - .yardopts
78
105
  - COPYING.md
@@ -311,30 +338,37 @@ files:
311
338
  - test/unit/yield_parameters_test.rb
312
339
  homepage: http://gofreerange.com/mocha/docs
313
340
  licenses: []
341
+
314
342
  post_install_message:
315
343
  rdoc_options: []
316
- require_paths:
344
+
345
+ require_paths:
317
346
  - lib
318
- required_ruby_version: !ruby/object:Gem::Requirement
347
+ required_ruby_version: !ruby/object:Gem::Requirement
319
348
  none: false
320
- requirements:
321
- - - ! '>='
322
- - !ruby/object:Gem::Version
323
- version: '0'
324
- segments:
349
+ requirements:
350
+ - - ">="
351
+ - !ruby/object:Gem::Version
352
+ hash: 3
353
+ segments:
325
354
  - 0
326
- hash: -4192078905680069090
327
- required_rubygems_version: !ruby/object:Gem::Requirement
355
+ version: "0"
356
+ required_rubygems_version: !ruby/object:Gem::Requirement
328
357
  none: false
329
- requirements:
330
- - - ! '>='
331
- - !ruby/object:Gem::Version
332
- version: '0'
358
+ requirements:
359
+ - - ">="
360
+ - !ruby/object:Gem::Version
361
+ hash: 3
362
+ segments:
363
+ - 0
364
+ version: "0"
333
365
  requirements: []
366
+
334
367
  rubyforge_project: mocha
335
- rubygems_version: 1.8.11
368
+ rubygems_version: 1.8.22
336
369
  signing_key:
337
370
  specification_version: 3
338
371
  summary: Mocking and stubbing library
339
372
  test_files: []
373
+
340
374
  has_rdoc: yard