surrogate 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
+ gemfiles/*.lock
4
5
  pkg/*
data/.travis.yml CHANGED
@@ -1,4 +1,8 @@
1
- nguage: ruby
1
+ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  script: "bundle exec rake"
5
+ gemfile:
6
+ - Gemfile
7
+ - gemfiles/rspec_mocks_2.2
8
+ - gemfiles/rspec_mocks_2.10
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in cobbler.gemspec
4
3
  gemspec
4
+
5
+ gem "rspec", "~> 2.2", group: :development
data/Readme.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://secure.travis-ci.org/JoshCheek/surrogate.png?branch=master)](http://travis-ci.org/JoshCheek/surrogate)
2
+
1
3
 
2
4
 
3
5
  About
@@ -446,7 +448,6 @@ TODO
446
448
  ----
447
449
 
448
450
  * Remove dependency on all of RSpec and only depend on rspec-core, then have AC tests for the other shit
449
- * Move surrogates to be first class and defined in the classes that use them.
450
451
  * Add proper failure messages for block invocations
451
452
  * Add a better explanation for motivations
452
453
  * Figure out whether I'm supposed to be using clone or dup for the object -.^ (looks like there may also be an `initialize_copy` method I can take advantage of instead of crazy stupid shit I'm doing now)
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://secure.travis-ci.org/JoshCheek/surrogate.png?branch=master)](http://travis-ci.org/JoshCheek/surrogate)
2
+
1
3
  <% setup do %>
2
4
  $LOAD_PATH.unshift '../lib', __FILE__
3
5
  require 'surrogate'
@@ -531,7 +533,6 @@ TODO
531
533
  ----
532
534
 
533
535
  * Remove dependency on all of RSpec and only depend on rspec-core, then have AC tests for the other shit
534
- * Move surrogates to be first class and defined in the classes that use them.
535
536
  * Add proper failure messages for block invocations
536
537
  * Add a better explanation for motivations
537
538
  * Figure out whether I'm supposed to be using clone or dup for the object -.^ (looks like there may also be an `initialize_copy` method I can take advantage of instead of crazy stupid shit I'm doing now)
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,8 @@
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
@@ -1,8 +1,8 @@
1
- require 'surrogate/rspec/have_been_told_to'
1
+ require 'surrogate/rspec/verb_matcher'
2
2
 
3
3
  class Surrogate
4
4
  module RSpec
5
- class HaveBeenInitializedWith < HaveBeenToldTo
5
+ class InitializationMatcher < VerbMatcher
6
6
  def initialize(*initialization_args, &block)
7
7
  super :initialize
8
8
  with *initialization_args, &block
@@ -2,7 +2,7 @@ require 'surrogate/rspec/invocation_matcher'
2
2
 
3
3
  class Surrogate
4
4
  module RSpec
5
- class HaveBeenAskedForIts < InvocationMatcher
5
+ class NounMatcher < InvocationMatcher
6
6
 
7
7
  class FailureMessageShouldDefault < AbstractFailureMessage
8
8
  def get_message
@@ -2,7 +2,7 @@ require 'surrogate/rspec/invocation_matcher'
2
2
 
3
3
  class Surrogate
4
4
  module RSpec
5
- class HaveBeenAskedIf < InvocationMatcher
5
+ class PredicateMatcher < InvocationMatcher
6
6
  class FailureMessageShouldDefault < AbstractFailureMessage
7
7
  def get_message
8
8
  "was never asked if #{ method_name }"
@@ -2,7 +2,7 @@ require 'surrogate/rspec/invocation_matcher'
2
2
 
3
3
  class Surrogate
4
4
  module RSpec
5
- class HaveBeenToldTo < InvocationMatcher
5
+ class VerbMatcher < InvocationMatcher
6
6
  class FailureMessageShouldDefault < AbstractFailureMessage
7
7
  def get_message
8
8
  "was never told to #{ method_name }"
@@ -70,6 +70,29 @@ class Surrogate
70
70
 
71
71
 
72
72
 
73
+ class RSpecMatchAsserter
74
+ attr_accessor :actual_invocation, :expected_invocation
75
+
76
+ def initialize(actual_invocation, expected_invocation)
77
+ self.actual_invocation, self.expected_invocation = actual_invocation, expected_invocation
78
+ end
79
+
80
+ def match?
81
+ rspec_arg_expectation = matcher_class.new *expected_invocation.args
82
+ rspec_arg_expectation.args_match? *actual_invocation.args
83
+ end
84
+
85
+ def matcher_class
86
+ return ::RSpec::Mocks::ArgumentListMatcher if approximate_2_11?
87
+ ::RSpec::Mocks::ArgumentExpectation
88
+ end
89
+
90
+ def approximate_2_11?
91
+ Gem::Requirement.create('~> 2.11').satisfied_by? Gem::Version.new(::RSpec::Mocks::Version::STRING)
92
+ end
93
+ end
94
+
95
+
73
96
 
74
97
  # rename args to invocation
75
98
  attr_accessor :expected_invocation, :block, :pass, :filter_name
@@ -112,8 +135,7 @@ class Surrogate
112
135
 
113
136
  def args_match?(actual_invocation)
114
137
  if RSpec.rspec_mocks_loaded?
115
- rspec_arg_expectation = ::RSpec::Mocks::ArgumentExpectation.new *expected_invocation.args
116
- rspec_arg_expectation.args_match? *actual_invocation.args
138
+ RSpecMatchAsserter.new(actual_invocation, expected_invocation).match?
117
139
  else
118
140
  expected_arguments == actual_arguments
119
141
  end
@@ -23,35 +23,35 @@ class Surrogate
23
23
 
24
24
  module Matchers
25
25
  def have_been_told_to(method_name)
26
- HaveBeenToldTo.new method_name
26
+ VerbMatcher.new method_name
27
27
  end
28
28
 
29
29
  def told_to(method_name)
30
- HaveBeenToldTo.new method_name
30
+ VerbMatcher.new method_name
31
31
  end
32
32
 
33
33
  def have_been_asked_if(method_name)
34
- HaveBeenAskedIf.new method_name
34
+ PredicateMatcher.new method_name
35
35
  end
36
36
 
37
37
  def asked_if(method_name)
38
- HaveBeenAskedIf.new method_name
38
+ PredicateMatcher.new method_name
39
39
  end
40
40
 
41
41
  def have_been_asked_for_its(method_name)
42
- HaveBeenAskedForIts.new method_name
42
+ NounMatcher.new method_name
43
43
  end
44
44
 
45
45
  def asked_for(method_name)
46
- HaveBeenAskedForIts.new method_name
46
+ NounMatcher.new method_name
47
47
  end
48
48
 
49
49
  def have_been_initialized_with(*initialization_args, &block)
50
- HaveBeenInitializedWith.new *initialization_args, &block
50
+ InitializationMatcher.new *initialization_args, &block
51
51
  end
52
52
 
53
53
  def initialized_with(*initialization_args, &block)
54
- HaveBeenInitializedWith.new *initialization_args, &block
54
+ InitializationMatcher.new *initialization_args, &block
55
55
  end
56
56
  end
57
57
  end
@@ -65,10 +65,10 @@ class Surrogate
65
65
  end
66
66
 
67
67
  require 'surrogate/rspec/substitute_for'
68
- require 'surrogate/rspec/have_been_asked_if'
69
- require 'surrogate/rspec/have_been_asked_for_its'
70
- require 'surrogate/rspec/have_been_initialized_with'
71
- require 'surrogate/rspec/have_been_told_to'
68
+ require 'surrogate/rspec/predicate_matcher'
69
+ require 'surrogate/rspec/noun_matcher'
70
+ require 'surrogate/rspec/initialization_matcher'
71
+ require 'surrogate/rspec/verb_matcher'
72
72
 
73
73
 
74
74
  RSpec.configure do |config|
@@ -1,3 +1,3 @@
1
1
  class Surrogate
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
data/surrogate.gemspec CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_runtime_dependency 'bindable_block', '= 0.0.5.1'
22
22
 
23
- s.add_development_dependency "rspec", '~> 2.2'
24
23
  s.add_development_dependency "rake"
25
- s.add_development_dependency "mountain_berry_fields", "~> 1.0.2"
24
+ s.add_development_dependency "rspec", "~> 2.2"
25
+ s.add_development_dependency "mountain_berry_fields", "~> 1.0.3"
26
26
  s.add_development_dependency "mountain_berry_fields-rspec", "~> 1.0.2"
27
27
  s.add_development_dependency "mountain_berry_fields-magic_comments", "~> 1.0.1"
28
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surrogate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-07 00:00:00.000000000 Z
12
+ date: 2012-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bindable_block
16
- requirement: &70330602486000 !ruby/object:Gem::Requirement
16
+ requirement: &70195439834980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,43 +21,43 @@ dependencies:
21
21
  version: 0.0.5.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70330602486000
24
+ version_requirements: *70195439834980
25
25
  - !ruby/object:Gem::Dependency
26
- name: rspec
27
- requirement: &70330602485480 !ruby/object:Gem::Requirement
26
+ name: rake
27
+ requirement: &70195439834560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - ~>
30
+ - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: '2.2'
32
+ version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70330602485480
35
+ version_requirements: *70195439834560
36
36
  - !ruby/object:Gem::Dependency
37
- name: rake
38
- requirement: &70330602485100 !ruby/object:Gem::Requirement
37
+ name: rspec
38
+ requirement: &70195439834020 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ! '>='
41
+ - - ~>
42
42
  - !ruby/object:Gem::Version
43
- version: '0'
43
+ version: '2.2'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70330602485100
46
+ version_requirements: *70195439834020
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mountain_berry_fields
49
- requirement: &70330602484560 !ruby/object:Gem::Requirement
49
+ requirement: &70195439833520 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 1.0.2
54
+ version: 1.0.3
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70330602484560
57
+ version_requirements: *70195439833520
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mountain_berry_fields-rspec
60
- requirement: &70330602484020 !ruby/object:Gem::Requirement
60
+ requirement: &70195439833060 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70330602484020
68
+ version_requirements: *70195439833060
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mountain_berry_fields-magic_comments
71
- requirement: &70330602483520 !ruby/object:Gem::Requirement
71
+ requirement: &70195439832600 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 1.0.1
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70330602483520
79
+ version_requirements: *70195439832600
80
80
  description: Framework to aid in handrolling mock/spy objects.
81
81
  email:
82
82
  - josh.cheek@gmail.com
@@ -91,6 +91,8 @@ files:
91
91
  - Rakefile
92
92
  - Readme.md
93
93
  - Readme.md.mountain_berry_fields
94
+ - gemfiles/rspec_mocks_2.10
95
+ - gemfiles/rspec_mocks_2.2
94
96
  - lib/surrogate.rb
95
97
  - lib/surrogate/api_comparer.rb
96
98
  - lib/surrogate/endower.rb
@@ -100,26 +102,26 @@ files:
100
102
  - lib/surrogate/options.rb
101
103
  - lib/surrogate/rspec.rb
102
104
  - lib/surrogate/rspec/abstract_failure_message.rb
103
- - lib/surrogate/rspec/have_been_asked_for_its.rb
104
- - lib/surrogate/rspec/have_been_asked_if.rb
105
- - lib/surrogate/rspec/have_been_initialized_with.rb
106
- - lib/surrogate/rspec/have_been_told_to.rb
105
+ - lib/surrogate/rspec/initialization_matcher.rb
107
106
  - lib/surrogate/rspec/invocation_matcher.rb
107
+ - lib/surrogate/rspec/noun_matcher.rb
108
+ - lib/surrogate/rspec/predicate_matcher.rb
108
109
  - lib/surrogate/rspec/substitute_for.rb
109
110
  - lib/surrogate/rspec/times_predicate.rb
111
+ - lib/surrogate/rspec/verb_matcher.rb
110
112
  - lib/surrogate/rspec/with_filter.rb
111
113
  - lib/surrogate/values.rb
112
114
  - lib/surrogate/version.rb
113
115
  - spec/acceptance_spec.rb
114
116
  - spec/defining_api_methods_spec.rb
115
117
  - spec/rspec/block_support_spec.rb
116
- - spec/rspec/matchers_for_initialization_spec.rb
117
- - spec/rspec/matchers_for_nouns_spec.rb
118
- - spec/rspec/matchers_for_predicates_spec.rb
119
- - spec/rspec/matchers_for_verbs_spec.rb
118
+ - spec/rspec/initialization_matcher_spec.rb
120
119
  - spec/rspec/messages_spec.rb
120
+ - spec/rspec/noun_matcher_spec.rb
121
+ - spec/rspec/predicate_matcher_spec.rb
121
122
  - spec/rspec/rspec_mocks_integration_spec.rb
122
123
  - spec/rspec/substitute_for_spec.rb
124
+ - spec/rspec/verb_matcher_spec.rb
123
125
  - spec/spec_helper.rb
124
126
  - spec/unit/api_comparer_spec.rb
125
127
  - surrogate.gemspec
@@ -151,13 +153,13 @@ test_files:
151
153
  - spec/acceptance_spec.rb
152
154
  - spec/defining_api_methods_spec.rb
153
155
  - spec/rspec/block_support_spec.rb
154
- - spec/rspec/matchers_for_initialization_spec.rb
155
- - spec/rspec/matchers_for_nouns_spec.rb
156
- - spec/rspec/matchers_for_predicates_spec.rb
157
- - spec/rspec/matchers_for_verbs_spec.rb
156
+ - spec/rspec/initialization_matcher_spec.rb
158
157
  - spec/rspec/messages_spec.rb
158
+ - spec/rspec/noun_matcher_spec.rb
159
+ - spec/rspec/predicate_matcher_spec.rb
159
160
  - spec/rspec/rspec_mocks_integration_spec.rb
160
161
  - spec/rspec/substitute_for_spec.rb
162
+ - spec/rspec/verb_matcher_spec.rb
161
163
  - spec/spec_helper.rb
162
164
  - spec/unit/api_comparer_spec.rb
163
165
  has_rdoc: