mocha 1.1.0 → 1.2.0

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.
@@ -64,6 +64,19 @@ class StubbingNonExistentAnyInstanceMethodTest < Mocha::TestCase
64
64
  assert_passed(test_result)
65
65
  end
66
66
 
67
+ def test_should_allow_stubbing_method_to_which_any_instance_responds
68
+ Mocha::Configuration.prevent(:stubbing_non_existent_method)
69
+ klass = Class.new do
70
+ def respond_to?(method, include_private = false)
71
+ (method == :method_to_which_instance_responds)
72
+ end
73
+ end
74
+ test_result = run_as_test do
75
+ klass.any_instance.stubs(:method_to_which_instance_responds)
76
+ end
77
+ assert_passed(test_result)
78
+ end
79
+
67
80
  def test_should_allow_stubbing_existing_protected_any_instance_method
68
81
  Mocha::Configuration.prevent(:stubbing_non_existent_method)
69
82
  klass = Class.new do
@@ -1,6 +1,8 @@
1
+ require 'mocha/ruby_version'
2
+
1
3
  module Assertions
2
- def assert_method_visiblity(object, method_name, visiblity)
3
- method_key = RUBY_VERSION < '1.9' ? method_name.to_s : method_name.to_sym
4
- assert object.send("#{visiblity}_methods", false).include?(method_key), "#{method_name} is not #{visiblity}"
4
+ def assert_method_visibility(object, method_name, visiblity)
5
+ method_key = Mocha::PRE_RUBY_V19 ? method_name.to_s : method_name.to_sym
6
+ assert object.send("#{visiblity}_methods").include?(method_key), "#{method_name} is not #{visiblity}"
5
7
  end
6
- end
8
+ end
@@ -20,7 +20,7 @@ class MinitestResult
20
20
  end
21
21
 
22
22
  def failures
23
- @tests.map(&:failures).flatten.select { |r| Minitest::Assertion === r }.map { |f| Failure.new(f) }
23
+ @tests.map(&:failures).flatten.select { |r| r.instance_of?(Minitest::Assertion) }.map { |f| Failure.new(f) }
24
24
  end
25
25
 
26
26
  def failure_count
@@ -32,7 +32,7 @@ class MinitestResult
32
32
  end
33
33
 
34
34
  def errors
35
- @tests.map(&:failures).flatten.select { |r| Minitest::UnexpectedError === r }
35
+ @tests.map(&:failures).flatten.select { |r| r.instance_of?(Minitest::UnexpectedError) }
36
36
  end
37
37
 
38
38
  def error_count
@@ -49,7 +49,7 @@ module TestRunner
49
49
 
50
50
  def assert_passed(test_result)
51
51
  flunk "Test failed unexpectedly with message: #{test_result.failures}" if test_result.failure_count > 0
52
- flunk "Test failed unexpectedly with message: #{test_result.errors}" if test_result.error_count > 0
52
+ flunk "Test failed unexpectedly with message: #{test_result.errors.map(&:exception)}" if test_result.error_count > 0
53
53
  end
54
54
 
55
55
  def assert_failed(test_result)
@@ -7,6 +7,7 @@ class AnyInstanceMethodTest < Mocha::TestCase
7
7
 
8
8
  include Mocha
9
9
 
10
+ unless RUBY_V2_PLUS
10
11
  def test_should_hide_original_method
11
12
  klass = Class.new { def method_x; end }
12
13
  method = AnyInstanceMethod.new(klass, :method_x)
@@ -15,6 +16,7 @@ class AnyInstanceMethodTest < Mocha::TestCase
15
16
 
16
17
  assert_equal false, klass.method_defined?(:method_x)
17
18
  end
19
+ end
18
20
 
19
21
  def test_should_not_raise_error_hiding_method_that_isnt_defined
20
22
  klass = Class.new
@@ -8,6 +8,7 @@ class ClassMethodTest < Mocha::TestCase
8
8
 
9
9
  include Mocha
10
10
 
11
+ unless RUBY_V2_PLUS
11
12
  def test_should_hide_original_method
12
13
  klass = Class.new { def self.method_x; end }
13
14
  method = ClassMethod.new(klass, :method_x)
@@ -16,6 +17,7 @@ class ClassMethodTest < Mocha::TestCase
16
17
 
17
18
  assert_equal false, klass.respond_to?(:method_x)
18
19
  end
20
+ end
19
21
 
20
22
  def test_should_not_raise_error_hiding_method_that_isnt_defined
21
23
  klass = Class.new
@@ -1,4 +1,5 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
+ require 'mocha/ruby_version'
2
3
  require 'mocha/mock'
3
4
  require 'mocha/expectation_error_factory'
4
5
  require 'set'
@@ -44,7 +45,7 @@ class MockTest < Mocha::TestCase
44
45
  assert_equal true, mock.eql?(mock)
45
46
  end
46
47
 
47
- if RUBY_VERSION < '1.9'
48
+ if PRE_RUBY_V19
48
49
  OBJECT_METHODS = STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS.reject { |m| m =~ /^__.*__$/ || ["method_missing", "singleton_method_undefined", "initialize"].include?(m)}
49
50
  else
50
51
  OBJECT_METHODS = STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS.reject { |m| m =~ /^__.*__$/ || [:object_id, :method_missing, :singleton_method_undefined, :initialize, :String, :singleton_method_added].include?(m) }
@@ -1,4 +1,5 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
+ require 'mocha/ruby_version'
2
3
  require 'mocha/inspect'
3
4
  require 'method_definer'
4
5
 
@@ -25,7 +26,7 @@ class ObjectInspectTest < Mocha::TestCase
25
26
  def test_should_use_underscored_id_instead_of_object_id_or_id_so_that_they_can_be_stubbed
26
27
  calls = []
27
28
  object = Object.new
28
- object.replace_instance_method(:id) { calls << :id; return 1 } if RUBY_VERSION < '1.9'
29
+ object.replace_instance_method(:id) { calls << :id; return 1 } if Mocha::PRE_RUBY_V19
29
30
  object.replace_instance_method(:object_id) { calls << :object_id; return 1 }
30
31
  object.replace_instance_method(:__id__) { calls << :__id__; return 1 }
31
32
  object.replace_instance_method(:inspect) { "object-description" }
@@ -1,6 +1,9 @@
1
1
  require File.expand_path('../../../test_helper', __FILE__)
2
2
 
3
3
  require 'mocha/parameter_matchers/includes'
4
+ require 'mocha/parameter_matchers/object'
5
+ require 'mocha/parameter_matchers/has_key'
6
+ require 'mocha/parameter_matchers/regexp_matches'
4
7
  require 'mocha/inspect'
5
8
 
6
9
  class IncludesTest < Mocha::TestCase
@@ -56,4 +59,44 @@ class IncludesTest < Mocha::TestCase
56
59
  matcher = includes(:x)
57
60
  assert !matcher.matches?([:x])
58
61
  end
62
+
63
+ def test_should_match_object_including_value_which_matches_nested_matcher
64
+ matcher = includes(has_key(:key))
65
+ assert matcher.matches?([[:non_matching_element, {:key => 'value'}]])
66
+ end
67
+
68
+ def test_should_not_match_object_which_doesnt_include_value_that_matches_nested_matcher
69
+ matcher = includes(has_key(:key))
70
+ assert !matcher.matches?([[:non_matching_element, {:other_key => 'other-value'}]])
71
+ end
72
+
73
+ def test_should_match_string_argument_containing_substring
74
+ matcher = includes('bar')
75
+ assert matcher.matches?(['foobarbaz'])
76
+ end
77
+
78
+ def test_should_not_match_string_argument_without_substring
79
+ matcher = includes('bar')
80
+ assert !matcher.matches?(['foobaz'])
81
+ end
82
+
83
+ def test_should_match_hash_argument_containing_given_key
84
+ matcher = includes(:key)
85
+ assert matcher.matches?([{:thing => 1, :key => 2}])
86
+ end
87
+
88
+ def test_should_not_match_hash_argument_missing_given_key
89
+ matcher = includes(:key)
90
+ assert !matcher.matches?([{:thing => 1, :other => :key}])
91
+ end
92
+
93
+ def test_should_match_hash_when_nested_matcher_matches_key
94
+ matcher = includes(regexp_matches(/ar/))
95
+ assert matcher.matches?([{'foo' => 1, 'bar' => 2}])
96
+ end
97
+
98
+ def test_should_not_match_hash_when_nested_matcher_doesn_not_match_key
99
+ matcher = includes(regexp_matches(/az/))
100
+ assert !matcher.matches?([{'foo' => 1, 'bar' => 2}])
101
+ end
59
102
  end
metadata CHANGED
@@ -1,85 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocha
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mead
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-13 00:00:00.000000000 Z
11
+ date: 2016-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metaclass
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.0.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: introspection
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.0.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.0.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: yard
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - '>='
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
75
  version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - '>='
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: redcarpet
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ~>
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: '1'
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ~>
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: '1'
96
+ version: '0'
83
97
  description: Mocking and stubbing library with JMock/SchMock syntax, which allows
84
98
  mocking and stubbing of methods on real (non-mock) classes.
85
99
  email: mocha-developer@googlegroups.com
@@ -87,8 +101,8 @@ executables: []
87
101
  extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
90
- - .gemtest
91
- - .yardopts
104
+ - ".gemtest"
105
+ - ".yardopts"
92
106
  - CONTRIBUTING.md
93
107
  - COPYING.md
94
108
  - Gemfile
@@ -199,6 +213,7 @@ files:
199
213
  - lib/mocha/pretty_parameters.rb
200
214
  - lib/mocha/receivers.rb
201
215
  - lib/mocha/return_values.rb
216
+ - lib/mocha/ruby_version.rb
202
217
  - lib/mocha/sequence.rb
203
218
  - lib/mocha/setup.rb
204
219
  - lib/mocha/single_return_value.rb
@@ -252,6 +267,7 @@ files:
252
267
  - test/acceptance/stub_instance_method_defined_on_object_class_test.rb
253
268
  - test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb
254
269
  - test/acceptance/stub_instance_method_defined_on_superclass_test.rb
270
+ - test/acceptance/stub_method_defined_on_module_and_aliased_test.rb
255
271
  - test/acceptance/stub_module_method_test.rb
256
272
  - test/acceptance/stub_test.rb
257
273
  - test/acceptance/stubba_example_test.rb
@@ -339,7 +355,9 @@ files:
339
355
  - yard-templates/default/layout/html/google_analytics.erb
340
356
  - yard-templates/default/layout/html/setup.rb
341
357
  homepage: http://gofreerange.com/mocha/docs
342
- licenses: []
358
+ licenses:
359
+ - MIT
360
+ - BSD-2-Clause
343
361
  metadata: {}
344
362
  post_install_message:
345
363
  rdoc_options: []
@@ -347,19 +365,18 @@ require_paths:
347
365
  - lib
348
366
  required_ruby_version: !ruby/object:Gem::Requirement
349
367
  requirements:
350
- - - '>='
368
+ - - ">="
351
369
  - !ruby/object:Gem::Version
352
370
  version: '0'
353
371
  required_rubygems_version: !ruby/object:Gem::Requirement
354
372
  requirements:
355
- - - '>='
373
+ - - ">="
356
374
  - !ruby/object:Gem::Version
357
375
  version: '0'
358
376
  requirements: []
359
377
  rubyforge_project: mocha
360
- rubygems_version: 2.0.14
378
+ rubygems_version: 2.5.1
361
379
  signing_key:
362
380
  specification_version: 3
363
381
  summary: Mocking and stubbing library
364
382
  test_files: []
365
- has_rdoc: yard