punchout 0.2.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 884d3dcab31235e809deb2c8d3f8779dd2f46dd5
4
- data.tar.gz: 298a8d3c298bb1f6b7b406d272d25c0720f5b1be
3
+ metadata.gz: be5727176805496ca238cc6392b0ac750e5d2244
4
+ data.tar.gz: 84513d9d9a99629c94e6401f8423c50fc639be57
5
5
  SHA512:
6
- metadata.gz: 5785de814f7d0923a21bf4dfb39d704e2d775911ed5af65e086dcb883849828d9f8594011ada36e74c819d611c7f7c56ef4790e4b098acf3b493399b943c0a87
7
- data.tar.gz: fb47608dad0bc974f5f81aa45048ff4cf9235b9761ce2d77b2b7834e5a215db4d34651e5124c8ece875bbf3588439dff92a6fcf7109256bb2e95abea5ea1b164
6
+ metadata.gz: 9552aee91cf84f2fdaad856951387519cc3e6a74a0401afa4d9d900883ef1b813d5801a1ad7f020454746c6a6410c4a0af53c87d826d49ae4e7066c8ff54ecc3
7
+ data.tar.gz: de32f2de50b3256552ca1f119cbaacd244be7b92abb5584ccec9278d62c22f40fcf4d89520d4e81c7508e41cd41621594ad562eec06fcb85aab103a75f809026
@@ -2,17 +2,35 @@ require 'punchout/puncher'
2
2
  require 'punchout/matcher/class'
3
3
 
4
4
  module Punchout
5
+ # Classes that include this module become punchable.
6
+ #
7
+ # Calling `Instance#punch(obj)`, will return a class, the
8
+ # class of which is determined by one or more characteristics of `obj`
5
9
  module Punchable
10
+
11
+ # Indicates whether this module is punchable
12
+ #
13
+ # TODO: This method might become an indication of whether any punchers are
14
+ # registered. Or it just might die. Not sure yet.
6
15
  def punchable?
7
16
  true
8
17
  end
9
18
 
19
+ # An instance of something that acts like a {Matcher}
10
20
  attr_accessor :matcher
11
21
 
22
+ # The {Puncher} assocated with this punchable.
23
+ #
24
+ # @return [Puncher] a {Puncher}
12
25
  def puncher
13
26
  @puncher ||= Puncher.new
14
27
  end
15
28
 
29
+ # Punches a class based on the object passed and the {Matcher}s tied to
30
+ # this {Punchable}
31
+ #
32
+ # @param obj The object that determines what we punch
33
+ # @return [Class] The {Class} that matched against `obj`
16
34
  def punch(obj)
17
35
  puncher.punch(obj)
18
36
  end
@@ -1,11 +1,14 @@
1
1
  require 'punchout/puncher/matchable'
2
2
 
3
3
  module Punchout
4
- class Matcher
4
+ # When a user calls {Punchable#punch} with a `candidate`, each {Matchable} will call {Matcher#matches?} until one returns true.
5
+ module Matcher
5
6
  def initialize(subject)
6
7
  @subject = subject
7
8
  end
8
9
 
10
+ # Creates a {Matchable} assocating this matcher with the thing it should
11
+ # return.
9
12
  def punches(thing)
10
13
  Punchout::Puncher::Matchable.new(self, thing)
11
14
  end
@@ -1,11 +1,14 @@
1
1
  require 'punchout/matcher'
2
2
 
3
3
  module Punchout
4
- class Matcher
5
- class Ancestry < Matcher
6
- def conflicts?(matcher)
4
+ module Matcher
5
+ # Matches when the candidate's class matches the subject class of this matcher, or any
6
+ # ancestor of that subject.
7
+ #
8
+ # `Matcher::Ancestry.new([]).matches?(Enumerable) => true`
9
+ class Ancestry
7
10
 
8
- end
11
+ include Punchout::Matcher
9
12
 
10
13
  def matches?(candidate)
11
14
  (@subject >= candidate.class) == true
@@ -1,11 +1,12 @@
1
1
  require 'punchout/matcher'
2
2
 
3
3
  module Punchout
4
- class Matcher
5
- class Klass < Matcher
6
- def conflicts?(matcher)
7
- false
8
- end
4
+ module Matcher
5
+ # Matches when the candidate's class matches the class of the subject of
6
+ # this matcher
7
+ class Klass
8
+
9
+ include Punchout::Matcher
9
10
 
10
11
  def matches?(candidate)
11
12
  @subject == candidate.class
@@ -1,11 +1,12 @@
1
1
  require 'punchout/matcher'
2
2
 
3
3
  module Punchout
4
- class Matcher
5
- class Equal < Matcher
6
- def conflicts?(matcher)
4
+ module Matcher
5
+ # Matches when the candidate matches the subject of this matcher, or any
6
+ # ancestor of that subject.
7
+ class Equal
7
8
 
8
- end
9
+ include Punchout::Matcher
9
10
 
10
11
  def matches?(candidate)
11
12
  @subject == candidate
@@ -1,11 +1,15 @@
1
1
  require 'punchout/matcher'
2
2
 
3
3
  module Punchout
4
- class Matcher
5
- class Progeny < Matcher
6
- def conflicts?(matcher)
4
+ module Matcher
5
+ # Matches when the candidate's class matches the subject class of this matcher, or any
6
+ # *descendant* of that subject.
7
+ #
8
+ # This Matcher is handy for punching against a set of classes that all
9
+ # mixin the same module.
10
+ class Progeny
7
11
 
8
- end
12
+ include Punchout::Matcher
9
13
 
10
14
  def matches?(candidate)
11
15
  (@subject <= candidate.class) == true
@@ -2,11 +2,20 @@ require 'punchout/puncher/matchable'
2
2
  require 'punchout/puncher/matchables'
3
3
 
4
4
  module Punchout
5
+ # Every {Punchable} has a {Puncher}, which keeps the details of
6
+ # implementation from littering the namespace of the {Punchable}
5
7
  class Puncher
6
8
  def initialize
7
9
  @matchables = Matchables.new
8
10
  end
9
11
 
12
+ # Adds passed {Matchable} to the list of things this {Puncher} can punch
13
+ #
14
+ # @param matchable [Matchable] a thing this puncher can match on and punch
15
+ # on behalf of
16
+ # @raise [StandardError] if matchable isn't a {Matchable}
17
+ #
18
+ #
10
19
  def add(matchable)
11
20
  if !matchable.kind_of?(Matchable)
12
21
  raise
@@ -15,10 +24,15 @@ module Punchout
15
24
  @matchables.add(matchable)
16
25
  end
17
26
 
27
+ # Indicates whether passed {::Class} is something this {Puncher} would punch
28
+ # if stimulated appropriately
18
29
  def can_punch?(type)
19
30
  @matchables.include?(type)
20
31
  end
21
32
 
33
+
34
+ #
35
+ # @return [Array] all of the {::Class}es that can be produced by this {Puncher}
22
36
  def all
23
37
  @matchables.all.map do |m|
24
38
  m.thing
@@ -33,6 +47,10 @@ module Punchout
33
47
  match.thing
34
48
  end
35
49
  end
50
+
51
+ def punch!(type)
52
+ punch(type) or raise
53
+ end
36
54
  end
37
55
  end
38
56
 
@@ -1,5 +1,10 @@
1
1
  module Punchout
2
2
  class Puncher
3
+ # Sanity checks and stores the Matchables behind a {Puncher}
4
+ #
5
+ # @note If two matchers would trigger on the item passed, the first
6
+ # matcher added wins.
7
+ #
3
8
  class Matchables
4
9
  def initialize
5
10
  @matchables = []
metadata CHANGED
@@ -1,92 +1,76 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: punchout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Carrel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-18 00:00:00.000000000 Z
11
+ date: 2016-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
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'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mocha
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: simplecov
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
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'
55
55
  description: A flexible implementation of the Registry pattern, with an extensible
56
56
  finder/matcher mechanism.
57
57
  email:
58
58
  - edward@carrel.org
59
- - ed@pocketchange.com
60
59
  executables: []
61
60
  extensions: []
62
61
  extra_rdoc_files: []
63
62
  files:
64
63
  - lib/punchout.rb
64
+ - lib/punchout/fabricable.rb
65
65
  - lib/punchout/fabricator.rb
66
- - lib/punchout/puncher/matchable.rb
67
- - lib/punchout/puncher/matchables.rb
68
- - lib/punchout/puncher/matchable/resolver.rb
69
66
  - lib/punchout/matcher.rb
70
- - lib/punchout/matcher/equal.rb
71
- - lib/punchout/matcher/class.rb
72
67
  - lib/punchout/matcher/ancestry.rb
68
+ - lib/punchout/matcher/class.rb
69
+ - lib/punchout/matcher/equal.rb
73
70
  - lib/punchout/matcher/progeny.rb
74
71
  - lib/punchout/puncher.rb
75
- - lib/punchout/fabricable.rb
76
- - test/unit/punchout_test.rb
77
- - test/unit/test_helper.rb
78
- - test/unit/punchout/puncher/matchables_test.rb
79
- - test/unit/punchout/puncher/matchable_test.rb
80
- - test/unit/punchout/matcher/ancestry_test.rb
81
- - test/unit/punchout/matcher/equal_test.rb
82
- - test/unit/punchout/matcher/class_test.rb
83
- - test/unit/punchout/matcher/progeny_test.rb
84
- - test/unit/punchout/matcher_test.rb
85
- - test/unit/punchout/fabricator_test.rb
86
- - test/unit/punchout/puncher_test.rb
87
- - test/integration/punchout_test.rb
88
- - test/integration/test_helper.rb
89
- - test/integration/punchout/fabricable_test.rb
72
+ - lib/punchout/puncher/matchable.rb
73
+ - lib/punchout/puncher/matchables.rb
90
74
  homepage:
91
75
  licenses:
92
76
  - MIT
@@ -97,17 +81,17 @@ require_paths:
97
81
  - lib
98
82
  required_ruby_version: !ruby/object:Gem::Requirement
99
83
  requirements:
100
- - - '>='
84
+ - - ">="
101
85
  - !ruby/object:Gem::Version
102
86
  version: '0'
103
87
  required_rubygems_version: !ruby/object:Gem::Requirement
104
88
  requirements:
105
- - - '>='
89
+ - - ">="
106
90
  - !ruby/object:Gem::Version
107
91
  version: '0'
108
92
  requirements: []
109
93
  rubyforge_project:
110
- rubygems_version: 2.0.14
94
+ rubygems_version: 2.5.1
111
95
  signing_key:
112
96
  specification_version: 4
113
97
  summary: A flexible registry pattern gem
@@ -1,15 +0,0 @@
1
- module Punchout
2
- class Puncher
3
- class Matchable
4
- class Resolver
5
- def initialize(matcher)
6
- @matcher = matcher
7
- end
8
-
9
- def build(thing)
10
- Matchable.new(@matcher,thing)
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,69 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- require 'punchout/fabricable'
4
- require 'punchout/matcher/class'
5
-
6
- class Punchout::Fabricator::Test < Test::Unit::TestCase
7
- class Factory
8
- def initialize(pairings)
9
- @pairings = pairings
10
- end
11
-
12
- def build(thing)
13
- matcher = Punchout::Matcher::Klass.new(thing)
14
- punchable = @pairings.find {|p| p[:match] == thing.class}[:punchable]
15
- matcher.punches(punchable)
16
- end
17
- end
18
-
19
- setup do
20
- punchout_klass = Class.new do
21
- include Punchout::Fabricable
22
-
23
- attr_accessor :factory
24
- end
25
-
26
- @pairings = 3.times.map {
27
- {match: Class.new, punchable: Class.new}
28
- }
29
-
30
- fabricator = punchout_klass.new
31
- fabricator.factory = Factory.new(@pairings)
32
-
33
- @puncher = fabricator.puncher
34
- end
35
-
36
-
37
- test "#punch exists" do
38
- @pairings.each do |p|
39
- matcher = Punchout::Matcher::Klass.new(p[:match])
40
-
41
- matchable = matcher.punches(p[:punchable])
42
-
43
- @puncher.add(matchable)
44
- end
45
-
46
- expected = @pairings.first
47
-
48
- expected_matching_instance = expected[:match].new
49
-
50
- result = @puncher.can_punch?(expected_matching_instance)
51
- assert result, "#{@puncher.inspect} CAN NOT PUNCH #{expected[:match]}"
52
-
53
- result = @puncher.punch(expected_matching_instance)
54
- assert_equal expected[:punchable],result
55
- end
56
-
57
- test "#punch does not exists" do
58
- expected = @pairings.first
59
-
60
- expected_matching_instance = expected[:match].new
61
-
62
- result = @puncher.can_punch?(expected_matching_instance)
63
- assert result, "#{@puncher.inspect} CAN NOT PUNCH #{expected[:match]}"
64
-
65
- result = @puncher.punch(expected_matching_instance)
66
- assert_equal expected[:punchable],result
67
- end
68
- end
69
-
@@ -1,57 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- require 'punchout'
4
- require 'punchout/matcher/class'
5
-
6
- class Punchout::Test < Test::Unit::TestCase
7
- setup do
8
- @punchout_klass = Class.new do
9
- include Punchout::Punchable
10
- end
11
-
12
- @pairings = 3.times.map {
13
- {match: Class.new, punchable: Class.new}
14
- }
15
- end
16
-
17
- test "#punch" do
18
- punchout = @punchout_klass.new
19
- puncher = punchout.puncher
20
-
21
- @pairings.each do |p|
22
- matcher = Punchout::Matcher::Klass.new(p[:match])
23
-
24
- matchable = matcher.punches(p[:punchable])
25
-
26
- puncher.add(matchable)
27
- end
28
-
29
- expected = @pairings.first
30
-
31
- expected_matching_instance = expected[:match].new
32
-
33
- result = puncher.can_punch?(expected_matching_instance)
34
- assert result, "#{punchout.puncher.inspect} CAN NOT PUNCH #{expected[:match]}"
35
-
36
- result = puncher.punch(expected_matching_instance)
37
- assert_equal expected[:punchable],result
38
- end
39
-
40
- test "#all" do
41
- punchout = @punchout_klass.new
42
- puncher = punchout.puncher
43
-
44
- @pairings.each do |p|
45
- matcher = Punchout::Matcher::Klass.new(p[:match])
46
-
47
- matchable = matcher.punches(p[:punchable])
48
-
49
- puncher.add(matchable)
50
- end
51
-
52
- expected = @pairings.map {|p| p[:punchable]}
53
-
54
- result = puncher.all
55
- assert_equal expected,result
56
- end
57
- end
@@ -1,16 +0,0 @@
1
- $:.push('lib')
2
-
3
- require 'coveralls'
4
- Coveralls.wear!
5
-
6
- if ENV["ENABLE_SIMPLE_COV"]
7
- require 'simplecov'
8
- # require File.expand_path('../simplecov_helper', __FILE__)
9
- SimpleCov.start do
10
- add_filter "test"
11
- add_group 'API', "lib"
12
- end
13
- end
14
-
15
- require 'test/unit/testcase'
16
- require 'mocha/setup'
@@ -1,48 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- require 'punchout/fabricator'
4
- require 'punchout/puncher'
5
-
6
- class Punchout::FabricatorTest < Test::Unit::TestCase
7
- setup do
8
- @mock_factory = mock
9
- @mock_puncher = mock
10
-
11
- Punchout::Puncher.expects(:new).returns(@mock_puncher)
12
-
13
- @fabricator = Punchout::Fabricator.new(@mock_factory)
14
-
15
- @mock_type = mock
16
- end
17
-
18
- test '#punch no match' do
19
- @mock_puncher.expects(:can_punch?).with(@mock_type).returns(false)
20
-
21
- mock_matchable = mock
22
- @mock_factory.expects(:build).with(@mock_type).returns(mock_matchable)
23
-
24
- @mock_puncher.expects(:add).with(mock_matchable)
25
-
26
- mock_thing = mock
27
- mock_matchable.expects(:thing).returns(mock_thing)
28
-
29
- result = @fabricator.punch(@mock_type)
30
-
31
- assert_equal mock_thing, result
32
- end
33
-
34
- test '#punch match located' do
35
- mock_thing = mock
36
-
37
- @mock_puncher.expects(:can_punch?).with(@mock_type).returns(true)
38
-
39
- @mock_puncher.expects(:punch).with(@mock_type).returns(mock_thing)
40
-
41
- @fabricator.instance_variable_set(:@matchables, @mock_matchables)
42
-
43
- result = @fabricator.punch(@mock_type)
44
-
45
- assert_equal mock_thing, result
46
- end
47
-
48
- end
@@ -1,46 +0,0 @@
1
- require File.expand_path('../../../test_helper', __FILE__)
2
-
3
- require 'punchout/matcher/ancestry'
4
-
5
- class Punchout::Matcher::AncestryTest < Test::Unit::TestCase
6
- setup do
7
- @ancestor_klass = Class.new
8
-
9
- @base_klass = Class.new(@ancestor_klass)
10
-
11
- @derived_klass = Class.new(@base_klass)
12
-
13
- @independent_klass = Class.new
14
-
15
- @mock_thing = mock
16
- end
17
-
18
- test "#match none" do
19
- matcher = Punchout::Matcher::Ancestry.new(@derived_klass)
20
- result = matcher.matches?(@independent_klass.new)
21
-
22
- assert_equal false, result
23
- end
24
-
25
- test "#match should match equivalence" do
26
- matcher = Punchout::Matcher::Ancestry.new(@base_klass)
27
- result = matcher.matches?(@base_klass.new)
28
-
29
- assert_equal true, result
30
- end
31
-
32
- test "#match should match descendant" do
33
- matcher = Punchout::Matcher::Ancestry.new(@base_klass)
34
- result = matcher.matches?(@derived_klass.new)
35
-
36
- assert_equal true, result
37
- end
38
-
39
- test "#match should not match ancestor" do
40
- matcher = Punchout::Matcher::Ancestry.new(@derived_klass)
41
- result = matcher.matches?(@base_klass.new)
42
-
43
- assert_equal false, result
44
- end
45
- end
46
-
@@ -1,48 +0,0 @@
1
-
2
- require File.expand_path('../../../test_helper', __FILE__)
3
-
4
- require 'punchout/matcher/class'
5
-
6
- class Punchout::Matcher::KlassTest < Test::Unit::TestCase
7
- setup do
8
- @ancestor_klass = Class.new
9
-
10
- @base_klass = Class.new(@ancestor_klass)
11
-
12
- @derived_klass = Class.new(@base_klass)
13
-
14
- @independent_klass = Class.new
15
-
16
- @mock_thing = mock
17
- end
18
-
19
- test "#match none" do
20
- matcher = Punchout::Matcher::Klass.new(@derived_klass)
21
- result = matcher.matches?(@independent_klass.new)
22
-
23
- assert_equal false, result
24
- end
25
-
26
- test "#match should match equivalence" do
27
- matcher = Punchout::Matcher::Klass.new(@base_klass)
28
- result = matcher.matches?(@base_klass.new)
29
-
30
- assert_equal true, result
31
- end
32
-
33
- test "#match should match descendant" do
34
- matcher = Punchout::Matcher::Klass.new(@base_klass)
35
- result = matcher.matches?(@derived_klass.new)
36
-
37
- assert_equal false, result
38
- end
39
-
40
- test "#match should not match ancestor" do
41
- matcher = Punchout::Matcher::Klass.new(@derived_klass)
42
- result = matcher.matches?(@base_klass.new)
43
-
44
- assert_equal false, result
45
- end
46
- end
47
-
48
-
@@ -1,17 +0,0 @@
1
-
2
- require File.expand_path('../../../test_helper', __FILE__)
3
-
4
- require 'punchout/matcher/equal'
5
-
6
- class Punchout::Matcher::EqualTest < Test::Unit::TestCase
7
- test "#match none" do
8
- matcher = Punchout::Matcher::Equal.new("foo")
9
- assert_equal false, matcher.matches?("bar")
10
- end
11
-
12
- test "#match should match equivalence" do
13
- matcher = Punchout::Matcher::Equal.new("foo")
14
- assert_equal true, matcher.matches?("foo")
15
- end
16
-
17
- end
@@ -1,47 +0,0 @@
1
- require File.expand_path('../../../test_helper', __FILE__)
2
-
3
- require 'punchout/matcher/progeny'
4
-
5
- class Punchout::Matcher::ProgenyTest < Test::Unit::TestCase
6
- setup do
7
- @ancestor_klass = Class.new
8
-
9
- @base_klass = Class.new(@ancestor_klass)
10
-
11
- @derived_klass = Class.new(@base_klass)
12
-
13
- @independent_klass = Class.new
14
-
15
- @mock_thing = mock
16
- end
17
-
18
- test "#match none" do
19
- matcher = Punchout::Matcher::Progeny.new(@derived_klass)
20
- result = matcher.matches?(@independent_klass.new)
21
-
22
- assert_equal false, result
23
- end
24
-
25
- test "#match should match equivalence" do
26
- matcher = Punchout::Matcher::Progeny.new(@base_klass)
27
- result = matcher.matches?(@base_klass.new)
28
-
29
- assert_equal true, result
30
- end
31
-
32
- test "#match should match descendant" do
33
- matcher = Punchout::Matcher::Progeny.new(@base_klass)
34
- result = matcher.matches?(@derived_klass.new)
35
-
36
- assert_equal false, result
37
- end
38
-
39
- test "#match should not match ancestor" do
40
- matcher = Punchout::Matcher::Progeny.new(@derived_klass)
41
- result = matcher.matches?(@base_klass.new)
42
-
43
- assert_equal true, result
44
- end
45
- end
46
-
47
-
@@ -1,22 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- require 'punchout/matcher'
4
-
5
- class Punchout::MatcherTest < Test::Unit::TestCase
6
- setup do
7
- @mock_subject = mock
8
- @matcher = Punchout::Matcher.new(@mock_subject)
9
- end
10
-
11
- test "#punches" do
12
- mock_thing = mock
13
-
14
- mock_matchable = mock
15
-
16
- Punchout::Puncher::Matchable.expects(:new).returns(mock_matchable)
17
-
18
- result = @matcher.punches(mock_thing)
19
-
20
- assert_equal result, mock_matchable
21
- end
22
- end
@@ -1,29 +0,0 @@
1
- require File.expand_path('../../../test_helper', __FILE__)
2
-
3
- require 'punchout/puncher/matchable'
4
-
5
- class Punchout::Puncher::MatchableTest < Test::Unit::TestCase
6
- test "#matches? true" do
7
- mock_matcher = mock
8
- mock_thing = mock
9
-
10
- mock_matcher.expects(:matches?).with(mock_thing).returns(true)
11
- matchable = Punchout::Puncher::Matchable.new(mock_matcher, mock_thing)
12
-
13
- result = matchable.matches?(mock_thing)
14
-
15
- assert_equal true, result
16
- end
17
-
18
- test "#matches? false" do
19
- mock_matcher = mock
20
- mock_thing = mock
21
-
22
- mock_matcher.expects(:matches?).with(mock_thing).returns(false)
23
- matchable = Punchout::Puncher::Matchable.new(mock_matcher, mock_thing)
24
-
25
- result = matchable.matches?(mock_thing)
26
-
27
- assert_equal false, result
28
- end
29
- end
@@ -1,73 +0,0 @@
1
- require File.expand_path('../../../test_helper', __FILE__)
2
-
3
- require 'punchout/puncher/matchables'
4
-
5
- class Punchout::Puncher::MatchablesTest < Test::Unit::TestCase
6
- setup do
7
-
8
- @mock_matchables = 5.times.map {|x|
9
- mock_matchable = mock
10
- mock_matchable.expects(:conflicts?).at_least_once.returns(false)
11
- mock_matchable
12
- }
13
-
14
- @matchables = Punchout::Puncher::Matchables.new
15
-
16
- @mock_matchables.each {|p|
17
- @matchables.add(p)
18
- }
19
-
20
- @mock_type = mock
21
- end
22
-
23
- test '#include? no match' do
24
- @mock_matchables.each {|p|
25
- p.expects(:matches?).with(@mock_type).returns(false)
26
- }
27
-
28
- result = @matchables.include?(@mock_type)
29
-
30
- assert_equal false, result
31
- end
32
-
33
- test '#include? match located' do
34
- @mock_matchables.take(4).each {|p|
35
- p.expects(:matches?).with(@mock_type).returns(false)
36
- }
37
-
38
-
39
- @mock_matchables.last.expects(:matches?).with(@mock_type).returns(true)
40
-
41
- result = @matchables.include?(@mock_type)
42
-
43
- assert_equal true, result
44
- end
45
-
46
- test '#fetch no match' do
47
- @mock_matchables.each {|p|
48
- p.expects(:matches?).with(@mock_type).returns(false)
49
- }
50
-
51
- result = @matchables.find(@mock_type)
52
-
53
- assert_equal nil, result
54
- end
55
-
56
- test '#fetch match located' do
57
- @mock_matchables.take(4).each {|p|
58
- p.expects(:matches?).with(@mock_type).returns(false)
59
- }
60
-
61
-
62
- @mock_matchables.last.expects(:matches?).with(@mock_type).returns(true)
63
-
64
- result = @matchables.find(@mock_type)
65
-
66
- assert_equal @mock_matchables.last, result
67
- end
68
-
69
- test '#all' do
70
- result = @matchables.all
71
- assert_equal @mock_matchables, result
72
- end
73
- end
@@ -1,59 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- require 'punchout/puncher'
4
-
5
- class Punchout::PuncherTest < Test::Unit::TestCase
6
- setup do
7
-
8
- @mock_matchables = mock
9
-
10
- @puncher = Punchout::Puncher.new
11
-
12
- @mock_type = mock
13
- end
14
-
15
- test '#punch no match' do
16
- @mock_matchables.expects(:find).with(@mock_type).returns(nil)
17
-
18
- @puncher.instance_variable_set(:@matchables, @mock_matchables)
19
-
20
- result = @puncher.punch(@mock_type)
21
-
22
- assert_equal nil, result
23
- end
24
-
25
- test '#punch match located' do
26
- mock_matchable = mock
27
-
28
- @mock_matchables.expects(:find).with(@mock_type).returns(mock_matchable)
29
-
30
- mock_thing = mock
31
- mock_matchable.expects(:thing).returns(mock_thing)
32
-
33
- @puncher.instance_variable_set(:@matchables, @mock_matchables)
34
-
35
- result = @puncher.punch(@mock_type)
36
-
37
- assert_equal mock_thing, result
38
- end
39
-
40
- test '#all' do
41
- mock_things = 5.times.map do
42
- mock
43
- end
44
-
45
- mock_matchable_arr = mock_things.map do |thing|
46
- mock_matchable = mock
47
- mock_matchable.expects(:thing).returns(thing)
48
- mock_matchable
49
- end
50
-
51
- @mock_matchables.expects(:all).returns(mock_matchable_arr)
52
-
53
- @puncher.instance_variable_set(:@matchables, @mock_matchables)
54
-
55
- result = @puncher.all
56
-
57
- assert_equal mock_things, result
58
- end
59
- end
@@ -1,74 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- require 'punchout'
4
-
5
- class Punchout::PunchableTest < Test::Unit::TestCase
6
- test "#include" do
7
- @klass = Class.new do
8
- include Punchout::Punchable
9
- end
10
- end
11
-
12
- test "#puncher greenfield" do
13
- @klass = Class.new do
14
- include Punchout::Punchable
15
- end
16
-
17
- instance = @klass.new
18
-
19
- mock_matcher_klass = mock
20
-
21
- mock_puncher = mock
22
- Punchout::Puncher.expects(:new).returns(mock_puncher)
23
-
24
- instance.matcher = mock_matcher_klass
25
-
26
- result = instance.puncher
27
-
28
- assert_equal mock_puncher, result
29
- end
30
-
31
- test "#puncher cached" do
32
- @klass = Class.new do
33
- include Punchout::Punchable
34
- end
35
-
36
- instance = @klass.new
37
-
38
- mock_matcher_klass = mock
39
-
40
- mock_puncher = mock
41
-
42
- instance.matcher = mock_matcher_klass
43
- instance.instance_variable_set(:@puncher, mock_puncher)
44
-
45
- result = instance.puncher
46
-
47
- assert_equal mock_puncher, result
48
- end
49
-
50
- test "#punch" do
51
- @klass = Class.new do
52
- include Punchout::Punchable
53
- end
54
-
55
- instance = @klass.new
56
-
57
- mock_matcher_klass = mock
58
-
59
- mock_puncher = mock
60
-
61
- instance.matcher = mock_matcher_klass
62
- instance.instance_variable_set(:@puncher, mock_puncher)
63
-
64
- mock_obj = mock
65
-
66
- mock_punched = mock
67
- mock_puncher.expects(:punch).with(mock_obj).returns(mock_punched)
68
-
69
- result = instance.punch(mock_obj)
70
-
71
- assert_equal mock_punched, result
72
- end
73
- end
74
-
@@ -1,15 +0,0 @@
1
- $:.push('lib')
2
-
3
- require 'coveralls'
4
- Coveralls.wear!
5
-
6
- if ENV["ENABLE_SIMPLE_COV"]
7
- require 'simplecov'
8
- SimpleCov.start do
9
- add_filter "test"
10
- add_group 'API', "lib"
11
- end
12
- end
13
-
14
- require 'test/unit/testcase'
15
- require 'mocha/setup'