surrogate 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e5519647b998e324731c5f4077ab0902717266ff
4
+ data.tar.gz: 28ddc396ed4f356a85ebf882466eab96cbb4b34f
5
+ SHA512:
6
+ metadata.gz: fcec1624106b21f4a9bfcc3966d311c8d53d7318f3eac6b1dfdc9268816a4a396d102f951f12c9f3086d2d684c941a69a4fc3dbcaf122b07c41887d3bcf3fb2f
7
+ data.tar.gz: e5e1e7233a828144ae186a0b057c4c4dd25296bad08bc6662be59c752ee653d653001a1beedc97681481a47a2e0a6daf59dc9bc3f81a7a8f4013782768288af7
data/.gitignore CHANGED
@@ -1,5 +1,4 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
- gemfiles/*.lock
5
4
  pkg/*
data/.travis.yml CHANGED
@@ -1,8 +1,14 @@
1
1
  language: ruby
2
+ script: "bundle exec rake"
2
3
  rvm:
3
4
  - 1.9.3
4
- script: "bundle exec rake"
5
- gemfile:
6
- - gemfiles/rspec_mocks_2.2
7
- - gemfiles/rspec_mocks_2.10
8
- - gemfiles/rspec_mocks_2.11
5
+ - 2.0.0
6
+ - 2.1.2
7
+ - ruby-head
8
+ - rbx-2
9
+ - jruby-head
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: ruby-head
13
+ - rvm: jruby-head
14
+ - rvm: rbx-2
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Rakefile CHANGED
@@ -10,8 +10,7 @@ RSpec::Core::RakeTask.new :rspec do |t|
10
10
  ]
11
11
  end
12
12
 
13
- require 'mountain_berry_fields/rake_task'
14
- MountainBerryFields::RakeTask.new :readme, 'Readme.md.mountain_berry_fields'
15
-
16
-
17
- task default: [:rspec, :readme]
13
+ # require 'mountain_berry_fields/rake_task'
14
+ # MountainBerryFields::RakeTask.new :readme, 'Readme.md.mountain_berry_fields'
15
+ # task default: [:rspec, :readme]
16
+ task default: :rspec
data/Readme.md CHANGED
@@ -92,8 +92,7 @@ end
92
92
  MockClient.new.request 3 # => ["result1", "result2", "result3"]
93
93
  ```
94
94
 
95
- You don't need a **default if you set the ivar** of the same name (replace `?` with `_p` for predicates, and `!` with `_b` for bang methods, since you can't have question marks or bangs in ivar names)
96
- Note that methods without bodies will not have their arguments checked, and will not be asserted against when comparing signatures.
95
+ You don't need a **default if you set the ivar** of the same name (replace `?` with `_p` for predicates, and `!` with `_b` for bang methods, since you can't have question marks or bangs in ivar names).
97
96
 
98
97
  ```ruby
99
98
  class MockClient
@@ -111,7 +110,7 @@ MockClient.new(12).id # => 12
111
110
  ```ruby
112
111
  class MockMP3
113
112
  Surrogate.endow self
114
- define :play # defaults are optional, will raise error if invoked without being told what to do
113
+ define :play # default behavior is to do nothing, same as empty block yielding nothing
115
114
  define :info
116
115
  end
117
116
 
@@ -114,8 +114,7 @@ MockClient.new.request 3 # => ["result1", "result2", "result3"]
114
114
  <% end %>
115
115
  ```
116
116
 
117
- You don't need a **default if you set the ivar** of the same name (replace `?` with `_p` for predicates, and `!` with `_b` for bang methods, since you can't have question marks or bangs in ivar names)
118
- Note that methods without bodies will not have their arguments checked, and will not be asserted against when comparing signatures.
117
+ You don't need a **default if you set the ivar** of the same name (replace `?` with `_p` for predicates, and `!` with `_b` for bang methods, since you can't have question marks or bangs in ivar names).
119
118
 
120
119
  ```ruby
121
120
  <% test 'overriding default by setting the ivar', with: :magic_comments do %>
@@ -136,7 +135,7 @@ MockClient.new(12).id # => 12
136
135
  <% test 'overriding default by invoking the method', with: :magic_comments do %>
137
136
  class MockMP3
138
137
  Surrogate.endow self
139
- define :play # defaults are optional, will raise error if invoked without being told what to do
138
+ define :play # default behavior is to do nothing, same as empty block yielding nothing
140
139
  define :info
141
140
  end
142
141
 
@@ -67,8 +67,10 @@ class Surrogate
67
67
 
68
68
  Endower.add_hook do |klass|
69
69
  klass.class_eval do
70
- alias was should
71
- alias was_not should_not
70
+ if respond_to?(:should)
71
+ alias was should
72
+ alias was_not should_not
73
+ end
72
74
  end
73
75
  end
74
76
  end
@@ -38,7 +38,7 @@ class Surrogate
38
38
  self
39
39
  end
40
40
 
41
- def failure_message_for_should
41
+ def failure_message
42
42
  message_for(
43
43
  if times_predicate.default? && with_filter.default?
44
44
  :FailureMessageShouldDefault
@@ -52,7 +52,7 @@ class Surrogate
52
52
  )
53
53
  end
54
54
 
55
- def failure_message_for_should_not
55
+ def failure_message_when_negated
56
56
  message_for(
57
57
  if times_predicate.default? && with_filter.default?
58
58
  :FailureMessageShouldNotDefault
@@ -15,7 +15,7 @@ class Surrogate
15
15
  end
16
16
 
17
17
 
18
- def failure_message_for_should
18
+ def failure_message
19
19
  extra_instance_methods = @comparison[:instance][:not_on_actual ].to_a # these come in as sets
20
20
  extra_class_methods = @comparison[:class ][:not_on_actual ].to_a
21
21
  missing_instance_methods = @comparison[:instance][:not_on_surrogate].to_a
@@ -44,7 +44,7 @@ class Surrogate
44
44
  "Was not substitutable because surrogate " << differences.join("\n")
45
45
  end
46
46
 
47
- def failure_message_for_should_not
47
+ def failure_message_when_negated
48
48
  "Should not have been substitute, but was"
49
49
  end
50
50
 
@@ -17,13 +17,17 @@ class Surrogate
17
17
  end
18
18
 
19
19
  def matcher_class
20
- return ::RSpec::Mocks::ArgumentListMatcher if approximate_2_11?
20
+ return ::RSpec::Mocks::ArgumentListMatcher if approximate_2_11? || approximate_3_0_0_rc?
21
21
  ::RSpec::Mocks::ArgumentExpectation
22
22
  end
23
23
 
24
24
  def approximate_2_11?
25
25
  Gem::Requirement.create('~> 2.11').satisfied_by? Gem::Version.new(::RSpec::Mocks::Version::STRING)
26
26
  end
27
+
28
+ def approximate_3_0_0_rc?
29
+ Gem::Requirement.create('~> 3.0.0.rc').satisfied_by? Gem::Version.new(::RSpec::Mocks::Version::STRING)
30
+ end
27
31
  end
28
32
 
29
33
 
@@ -1,3 +1,3 @@
1
1
  class Surrogate
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -172,8 +172,8 @@ describe 'define' do
172
172
  it 'has the same arity as the method' do
173
173
  mocked_class.define(:meth) { |a| a }
174
174
  mocked_class.new.meth(1).should == 1
175
- expect { mocked_class.new.meth }.to raise_error ArgumentError, /0 for 1/
176
- expect { mocked_class.new.meth 1, 2 }.to raise_error ArgumentError, /2 for 1/
175
+ expect { mocked_class.new.meth }.to raise_error ArgumentError, /0(, expected| for) 1/
176
+ expect { mocked_class.new.meth 1, 2 }.to raise_error ArgumentError, /2(, expected| for) 1/
177
177
  end
178
178
 
179
179
  it "can be defined with symbols or strings" do
@@ -219,7 +219,7 @@ describe 'define' do
219
219
  it 'raises arity errors, even if the value is overridden' do
220
220
  mocked_class.define(:meth) { }
221
221
  instance.instance_variable_set :@meth, "abc"
222
- expect { instance.meth "extra", "args" }.to raise_error ArgumentError, /wrong number of arguments \(2 for 0\)/
222
+ expect { instance.meth "extra", "args" }.to raise_error ArgumentError, /2(, expected| for) 0/
223
223
  end
224
224
 
225
225
  it 'treats bastard methods as having no arity' do
@@ -199,7 +199,7 @@ describe 'substutability matchers' do
199
199
  end
200
200
 
201
201
  it 'disregards when real object has natively implemented methods that cannot be reflected on' do
202
- Array.method(:[]).parameters.should == [[:rest]] # make sure Array signatures aren't changing across versions or something
202
+ next unless Array.method(:[]).parameters == [[:rest]] # e.g. rbx names all their params, so we can reflect to some extent
203
203
  Array.instance_method(:insert).parameters.should == [[:rest]]
204
204
  surrogate = Surrogate.endow(Class.new) { define(:[]) { |a,b,c| } }.define(:insert) { |a,b,c| }
205
205
  Array.should substitute_for surrogate, subset: true, types: true
@@ -311,7 +311,7 @@ describe 'substutability matchers' do
311
311
  end
312
312
 
313
313
  it 'disregards when real object has natively implemented methods that cannot be reflected on' do
314
- Array.method(:[]).parameters.should == [[:rest]] # make sure Array signatures aren't changing across versions or something
314
+ next unless Array.method(:[]).parameters == [[:rest]] # not all implementations do this
315
315
  Array.instance_method(:insert).parameters.should == [[:rest]]
316
316
  surrogate = Surrogate.endow(Class.new) { define(:[]) { |a,b,c| } }.define(:insert) { |a,b,c| }
317
317
  Array.should substitute_for surrogate, subset: true, names: true
@@ -40,13 +40,30 @@ describe Surrogate::ArgumentErrorizer do
40
40
  end
41
41
 
42
42
  it 'has useful error messages' do
43
- assert_message ->(){}, [1], "wrong number of arguments (1 for 0) in #{meth_name}()"
44
- assert_message ->(a){}, [], "wrong number of arguments (0 for 1) in #{meth_name}(a)"
45
- assert_message ->(a){}, [], "wrong number of arguments (0 for 1) in #{meth_name}(a)"
46
- assert_message ->(a=1){}, [1,2], "wrong number of arguments (2 for 1) in #{meth_name}(a='?')"
47
- assert_message ->(a, *b){}, [], "wrong number of arguments (0 for 1) in #{meth_name}(a, *b)"
48
- assert_message ->(a, *b, &c){}, [], "wrong number of arguments (0 for 1) in #{meth_name}(a, *b, &c)"
49
- assert_message ->(a, b, c=1, d=1, *e, f, &g){}, [], "wrong number of arguments (0 for 3) in #{meth_name}(a, b, c='?', d='?', *e, f, &g)"
43
+ if defined?(RUBY_PLATFORM) && RUBY_ENGINE == 'rbx'
44
+ assert_message ->(){}, [1], /given 1, expected 0 in #{meth_name}\(\)/
45
+ assert_message ->(a){}, [], /given 0, expected 1 in #{meth_name}\(a\)/
46
+ assert_message ->(a){}, [], /given 0, expected 1 in #{meth_name}\(a\)/
47
+ assert_message ->(a=1){}, [1,2], /given 2, expected 0 in #{meth_name}\(a='\?'\)/
48
+ assert_message ->(a, *b){}, [], /given 0, expected 1+ in #{meth_name}\(a, \*b\)/
49
+ assert_message ->(a, *b, &c){}, [], /given 0, expected 1+ in #{meth_name}\(a, \*b, &c\)/
50
+ assert_message ->(a, b, c=1, d=1, *e, f, &g){}, [], /given 0, expected 3+ in #{meth_name}\(a, b, c='\?', d='\?', \*e, f, &g\)/
51
+ else
52
+ assert_message ->(){}, [1], "wrong number of arguments (1 for 0) in #{meth_name}()"
53
+ assert_message ->(a){}, [], "wrong number of arguments (0 for 1) in #{meth_name}(a)"
54
+ assert_message ->(a){}, [], "wrong number of arguments (0 for 1) in #{meth_name}(a)"
55
+ if RUBY_VERSION == '1.9.3'
56
+ assert_message ->(a=1){}, [1,2], "wrong number of arguments (2 for 1) in #{meth_name}(a='?')"
57
+ assert_message ->(a, *b){}, [], "wrong number of arguments (0 for 1) in #{meth_name}(a, *b)"
58
+ assert_message ->(a, *b, &c){}, [], "wrong number of arguments (0 for 1) in #{meth_name}(a, *b, &c)"
59
+ assert_message ->(a, b, c=1, d=1, *e, f, &g){}, [], "wrong number of arguments (0 for 3) in #{meth_name}(a, b, c='?', d='?', *e, f, &g)"
60
+ else
61
+ assert_message ->(a=1){}, [1,2], "wrong number of arguments (2 for 0..1) in #{meth_name}(a='?')"
62
+ assert_message ->(a, *b){}, [], "wrong number of arguments (0 for 1+) in #{meth_name}(a, *b)"
63
+ assert_message ->(a, *b, &c){}, [], "wrong number of arguments (0 for 1+) in #{meth_name}(a, *b, &c)"
64
+ assert_message ->(a, b, c=1, d=1, *e, f, &g){}, [], "wrong number of arguments (0 for 3+) in #{meth_name}(a, b, c='?', d='?', *e, f, &g)"
65
+ end
66
+ end
50
67
  end
51
68
 
52
69
  it 'raises an ArgumentError if initialized with a non lambda/method' do
data/surrogate.gemspec CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_development_dependency "rake"
22
- s.add_development_dependency "rspec", "~> 2.4"
23
- s.add_development_dependency "mountain_berry_fields", "~> 1.0.3"
24
- s.add_development_dependency "mountain_berry_fields-rspec", "~> 1.0.3"
25
- s.add_development_dependency "mountain_berry_fields-magic_comments", "~> 1.0.1"
22
+ s.add_development_dependency "rspec", "~> 3.0"
23
+ # s.add_development_dependency "mountain_berry_fields", "~> 1.0.3"
24
+ # s.add_development_dependency "mountain_berry_fields-rspec", "~> 1.0.3"
25
+ # s.add_development_dependency "mountain_berry_fields-magic_comments", "~> 1.0.1"
26
26
  end
metadata CHANGED
@@ -1,71 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surrogate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
5
- prerelease:
4
+ version: 0.8.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Josh Cheek
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-11 00:00:00.000000000 Z
11
+ date: 2014-08-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
- requirement: &70341864482800 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *70341864482800
25
- - !ruby/object:Gem::Dependency
26
- name: rspec
27
- requirement: &70341864481800 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '2.4'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70341864481800
36
- - !ruby/object:Gem::Dependency
37
- name: mountain_berry_fields
38
- requirement: &70341864496820 !ruby/object:Gem::Requirement
39
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
40
23
  requirements:
41
- - - ~>
24
+ - - ">="
42
25
  - !ruby/object:Gem::Version
43
- version: 1.0.3
44
- type: :development
45
- prerelease: false
46
- version_requirements: *70341864496820
26
+ version: '0'
47
27
  - !ruby/object:Gem::Dependency
48
- name: mountain_berry_fields-rspec
49
- requirement: &70341864496280 !ruby/object:Gem::Requirement
50
- none: false
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
51
30
  requirements:
52
- - - ~>
31
+ - - "~>"
53
32
  - !ruby/object:Gem::Version
54
- version: 1.0.3
33
+ version: '3.0'
55
34
  type: :development
56
35
  prerelease: false
57
- version_requirements: *70341864496280
58
- - !ruby/object:Gem::Dependency
59
- name: mountain_berry_fields-magic_comments
60
- requirement: &70341864495600 !ruby/object:Gem::Requirement
61
- none: false
36
+ version_requirements: !ruby/object:Gem::Requirement
62
37
  requirements:
63
- - - ~>
38
+ - - "~>"
64
39
  - !ruby/object:Gem::Version
65
- version: 1.0.1
66
- type: :development
67
- prerelease: false
68
- version_requirements: *70341864495600
40
+ version: '3.0'
69
41
  description: Framework to aid in handrolling mock/spy objects.
70
42
  email:
71
43
  - josh.cheek@gmail.com
@@ -73,16 +45,13 @@ executables: []
73
45
  extensions: []
74
46
  extra_rdoc_files: []
75
47
  files:
76
- - .gitignore
77
- - .rvmrc
78
- - .travis.yml
48
+ - ".gitignore"
49
+ - ".travis.yml"
79
50
  - Changelog.md
51
+ - Gemfile
80
52
  - Rakefile
81
53
  - Readme.md
82
54
  - Readme.md.mountain_berry_fields
83
- - gemfiles/rspec_mocks_2.10
84
- - gemfiles/rspec_mocks_2.11
85
- - gemfiles/rspec_mocks_2.2
86
55
  - lib/surrogate.rb
87
56
  - lib/surrogate/api_comparer.rb
88
57
  - lib/surrogate/argument_errorizer.rb
@@ -126,27 +95,26 @@ files:
126
95
  - todo
127
96
  homepage: https://github.com/JoshCheek/surrogate
128
97
  licenses: []
98
+ metadata: {}
129
99
  post_install_message:
130
100
  rdoc_options: []
131
101
  require_paths:
132
102
  - lib
133
103
  required_ruby_version: !ruby/object:Gem::Requirement
134
- none: false
135
104
  requirements:
136
- - - ! '>='
105
+ - - ">="
137
106
  - !ruby/object:Gem::Version
138
107
  version: '0'
139
108
  required_rubygems_version: !ruby/object:Gem::Requirement
140
- none: false
141
109
  requirements:
142
- - - ! '>='
110
+ - - ">="
143
111
  - !ruby/object:Gem::Version
144
112
  version: '0'
145
113
  requirements: []
146
114
  rubyforge_project: surrogate
147
- rubygems_version: 1.8.11
115
+ rubygems_version: 2.2.2
148
116
  signing_key:
149
- specification_version: 3
117
+ specification_version: 4
150
118
  summary: Framework to aid in handrolling mock/spy objects.
151
119
  test_files:
152
120
  - spec/acceptance_spec.rb
@@ -164,4 +132,3 @@ test_files:
164
132
  - spec/unit/api_comparer_spec.rb
165
133
  - spec/unit/argument_errorizer_spec.rb
166
134
  - spec/unit/map_method_name_to_ivar_spec.rb
167
- has_rdoc:
data/.rvmrc DELETED
@@ -1,7 +0,0 @@
1
- rvm use ruby-1.9.3-p125
2
-
3
- root_dir="$(pwd)"
4
-
5
- alias ac="rspec '$root_dir/spec/acceptance_spec.rb'"
6
- alias sp="rspec $(find "$root_dir/spec" -name *_spec.rb | ruby -ne 'print unless /acceptance_spec/' | tr '\n' ' ')"
7
-
@@ -1,8 +0,0 @@
1
- # set this with
2
- # export BUNDLE_GEMFILE=gemfiles/rspec_mocks_2.10
3
-
4
- source "http://rubygems.org"
5
-
6
- gemspec path: File.expand_path('../..', __FILE__)
7
-
8
- gem "rspec", "= 2.10", group: :development
@@ -1,8 +0,0 @@
1
- # set this with
2
- # export BUNDLE_GEMFILE=gemfiles/rspec_mocks_2.11
3
-
4
- source "http://rubygems.org"
5
-
6
- gemspec path: File.expand_path('../..', __FILE__)
7
-
8
- gem "rspec", "~> 2.11", group: :development # squiggly is on purpose
@@ -1,8 +0,0 @@
1
- # set this with
2
- # export BUNDLE_GEMFILE=gemfiles/rspec_mocks_2.2
3
-
4
- source "http://rubygems.org"
5
-
6
- gemspec path: File.expand_path('../..', __FILE__)
7
-
8
- gem "rspec", "= 2.2", group: :development