representable_matchers 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +4 -1
- data/lib/matchers/base_matcher.rb +63 -0
- data/lib/matchers/extension_of_matcher.rb +34 -0
- data/lib/matchers/have_representable_collection_matcher.rb +31 -0
- data/lib/matchers/have_representable_property_matcher.rb +3 -50
- data/lib/matchers/parse_strategy_matcher.rb +34 -0
- data/lib/matchers/representable_collection_matcher.rb +34 -0
- data/lib/matchers/version.rb +1 -1
- data/lib/representable_matchers.rb +6 -1
- data/spec/matchers/base_matchers_spec.rb +43 -0
- data/spec/matchers/class_name_matcher_spec.rb +2 -5
- data/spec/matchers/extension_of_matcher_spec.rb +36 -0
- data/spec/matchers/have_representable_collection_matcher_spec.rb +38 -0
- data/spec/matchers/have_representable_property_matcher_spec.rb +59 -7
- data/spec/matchers/parse_strategy_matcher_spec.rb +35 -0
- data/spec/matchers/representable_attribute_matcher_spec.rb +2 -4
- data/spec/matchers/representable_collection_matcher_spec.rb +36 -0
- data/spec/support/fake_representable.rb +5 -1
- data/spec/support/shared_examples.rb +5 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjNmNGE2OGI1YWM3OThiYTRhOGM5NDEwMjc2YmI1MGY4YjM2NWY0Zg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODk1MWQxOTQ4NGViZjMzNWY0NDExMzhlY2U4ODRkMzE3ZWE1YTIyNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDI4M2MzYzczMWNiNGY3ZDJjYjU4MDNmODc2NzVhMTA3MzlmZmRmNjBjYzUw
|
10
|
+
ZGFlZGExNzQ0MGRiZGViMWJjNTRkZjY5MmVkZGI0ZTM5YmUyZjMxMTUyZDgx
|
11
|
+
YjFmMjBhNzg2NzlmNDQzN2IwZTE5NzEzMTdmNjMxZjEzNmNhMmQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDU5M2ZkNDU0OGFlNGExY2I3MzQzMjZjODg1NGFiMjNlMTk0ZjgwMGZiZTAw
|
14
|
+
ZDM5YmQ1NGNhYWIzYmJhMjJhZGFlYWNiOTk1NmJlM2RhNTc5Mjg5N2ZkMmIy
|
15
|
+
ZDU4OTkwYWVlZGJjMzYzZDZiNTljZDE1YmY0MGM3ODhlNmRiODk=
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Representable Matchers
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/CodingZeal/representable_matchers.png?branch=master)](https://travis-ci.org/CodingZeal/representable_matchers) [![Code Climate](https://codeclimate.com/github/CodingZeal/representable_matchers.png)](https://codeclimate.com/github/CodingZeal/representable_matchers)
|
3
|
+
[![Build Status](https://travis-ci.org/CodingZeal/representable_matchers.png?branch=master)](https://travis-ci.org/CodingZeal/representable_matchers) [![Code Climate](https://codeclimate.com/github/CodingZeal/representable_matchers.png)](https://codeclimate.com/github/CodingZeal/representable_matchers) [![Gem Version](https://badge.fury.io/rb/representable_matchers.png)](http://badge.fury.io/rb/representable_matchers)
|
4
4
|
|
5
5
|
Shoulda-style RSpec/Test Unit matchers for the Representable Gem
|
6
6
|
|
@@ -21,10 +21,13 @@ Or install it yourself as:
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
it { should have_representable_property(:name) }
|
24
|
+
it { should have_representable_collection(:children) }
|
24
25
|
|
25
26
|
With submatchers
|
26
27
|
|
27
28
|
it { should have_representable_property(:name).class_name("String") }
|
29
|
+
it { should have_representable_property(:class_and_extension).class_name("Array").extends(AbstractRepresenter) }
|
30
|
+
it { should have_representable_collection(:children).class_name("Array").extends(AbstractRepresenter).parse_strategy(:sync) }
|
28
31
|
|
29
32
|
## Contributing
|
30
33
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Representable
|
2
|
+
module Matchers
|
3
|
+
class BaseMatcher
|
4
|
+
|
5
|
+
def initialize(property)
|
6
|
+
@property = property
|
7
|
+
end
|
8
|
+
|
9
|
+
def class_name(class_name)
|
10
|
+
add_submatcher(ClassNameMatcher.new(@property, class_name))
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def extends(extension)
|
15
|
+
add_submatcher(ExtensionOfMatcher.new(@property, extension))
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def matches?(subject)
|
20
|
+
@subject = subject
|
21
|
+
submatchers_match?
|
22
|
+
end
|
23
|
+
|
24
|
+
def description
|
25
|
+
""
|
26
|
+
end
|
27
|
+
|
28
|
+
def failure_message_for_should
|
29
|
+
submatcher_failure_messages_for_should.last or raise "Undefined failure message for should"
|
30
|
+
end
|
31
|
+
|
32
|
+
def failure_message_for_should_not
|
33
|
+
submatcher_failure_messages_for_should_not.last or raise "Undefined failure message for should not"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def submatchers
|
39
|
+
@submatchers ||= []
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_submatcher(submatcher)
|
43
|
+
submatchers << submatcher
|
44
|
+
end
|
45
|
+
|
46
|
+
def submatchers_match?
|
47
|
+
failing_submatchers.empty?
|
48
|
+
end
|
49
|
+
|
50
|
+
def failing_submatchers
|
51
|
+
@failing_submatchers ||= submatchers.select { |matcher| !matcher.matches?(@subject) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def submatcher_failure_messages_for_should
|
55
|
+
failing_submatchers.map(&:failure_message_for_should)
|
56
|
+
end
|
57
|
+
|
58
|
+
def submatcher_failure_messages_for_should_not
|
59
|
+
failing_submatchers.map(&:failure_message_for_should_not)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Representable
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class ExtensionOfMatcher < Struct.new(:property, :extension)
|
5
|
+
|
6
|
+
def matches?(subject)
|
7
|
+
@subject = subject
|
8
|
+
matches_extension?
|
9
|
+
end
|
10
|
+
|
11
|
+
def description
|
12
|
+
"only allow representable properties extending specific representers"
|
13
|
+
end
|
14
|
+
|
15
|
+
def failure_message_for_should
|
16
|
+
"Expected #{expectation}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def failure_message_for_should_not
|
20
|
+
"Did not expect #{expectation}"
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def matches_extension?
|
26
|
+
@subject.send(:representable_attrs)[property].options[:extend] == extension
|
27
|
+
end
|
28
|
+
|
29
|
+
def expectation
|
30
|
+
"#{@subject.class} to be a representation of #{extension}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Representable
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
def have_representable_collection(property)
|
5
|
+
HaveRepresentableCollectionMatcher.new(property)
|
6
|
+
end
|
7
|
+
|
8
|
+
class HaveRepresentableCollectionMatcher < BaseMatcher
|
9
|
+
|
10
|
+
def initialize(property)
|
11
|
+
super(property)
|
12
|
+
add_representable_collection_submatcher
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse_strategy(strategy)
|
16
|
+
add_submatcher(ParseStrategyMatcher.new(@property, strategy))
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def description
|
21
|
+
"only allow properties being represented by Representable"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def add_representable_collection_submatcher
|
27
|
+
add_submatcher(RepresentableCollectionMatcher.new(@property))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -5,38 +5,15 @@ module Representable
|
|
5
5
|
HaveRepresentablePropertyMatcher.new(property)
|
6
6
|
end
|
7
7
|
|
8
|
-
class HaveRepresentablePropertyMatcher
|
8
|
+
class HaveRepresentablePropertyMatcher < BaseMatcher
|
9
9
|
|
10
10
|
def initialize(property)
|
11
|
-
|
11
|
+
super(property)
|
12
12
|
add_representable_property_submatcher
|
13
13
|
end
|
14
14
|
|
15
|
-
def class_name(class_name)
|
16
|
-
add_submatcher(ClassNameMatcher.new(@property, class_name))
|
17
|
-
self
|
18
|
-
end
|
19
|
-
|
20
|
-
def extends(extension)
|
21
|
-
add_submatcher(ExtensionOfMatcher.new(@property, extension))
|
22
|
-
self
|
23
|
-
end
|
24
|
-
|
25
|
-
def matches?(subject)
|
26
|
-
@subject = subject
|
27
|
-
submatchers_match?
|
28
|
-
end
|
29
|
-
|
30
15
|
def description
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
def failure_message_for_should
|
35
|
-
submatcher_failure_messages_for_should.last
|
36
|
-
end
|
37
|
-
|
38
|
-
def failure_message_for_should_not
|
39
|
-
submatcher_failure_messages_for_should_not.last
|
16
|
+
"only allow properties being represented by Representable"
|
40
17
|
end
|
41
18
|
|
42
19
|
private
|
@@ -44,30 +21,6 @@ module Representable
|
|
44
21
|
def add_representable_property_submatcher
|
45
22
|
add_submatcher(RepresentablePropertyMatcher.new(@property))
|
46
23
|
end
|
47
|
-
|
48
|
-
def submatchers
|
49
|
-
@submatchers ||= []
|
50
|
-
end
|
51
|
-
|
52
|
-
def add_submatcher(submatcher)
|
53
|
-
submatchers << submatcher
|
54
|
-
end
|
55
|
-
|
56
|
-
def submatchers_match?
|
57
|
-
failing_submatchers.empty?
|
58
|
-
end
|
59
|
-
|
60
|
-
def failing_submatchers
|
61
|
-
@failing_submatchers ||= submatchers.select { |matcher| !matcher.matches?(@subject) }
|
62
|
-
end
|
63
|
-
|
64
|
-
def submatcher_failure_messages_for_should
|
65
|
-
failing_submatchers.map(&:failure_message_for_should)
|
66
|
-
end
|
67
|
-
|
68
|
-
def submatcher_failure_messages_for_should_not
|
69
|
-
failing_submatchers.map(&:failure_message_for_should_not)
|
70
|
-
end
|
71
24
|
end
|
72
25
|
end
|
73
26
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Representable
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class ParseStrategyMatcher < Struct.new(:property, :strategy)
|
5
|
+
|
6
|
+
def matches?(subject)
|
7
|
+
@subject = subject
|
8
|
+
matches_strategy?
|
9
|
+
end
|
10
|
+
|
11
|
+
def description
|
12
|
+
"only allow representable collection to use a specific parse strategy"
|
13
|
+
end
|
14
|
+
|
15
|
+
def failure_message_for_should
|
16
|
+
"Expected #{expectation}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def failure_message_for_should_not
|
20
|
+
"Did not expect #{expectation}"
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def matches_strategy?
|
26
|
+
@subject.send(:representable_attrs)[property].options[:parse_strategy] == strategy
|
27
|
+
end
|
28
|
+
|
29
|
+
def expectation
|
30
|
+
"#{@subject.class} to be a kind of #{strategy}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Representable
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class RepresentableCollectionMatcher < Struct.new(:property)
|
5
|
+
|
6
|
+
def matches?(subject)
|
7
|
+
@subject = subject
|
8
|
+
collection?
|
9
|
+
end
|
10
|
+
|
11
|
+
def description
|
12
|
+
"only allow representable collection"
|
13
|
+
end
|
14
|
+
|
15
|
+
def failure_message_for_should
|
16
|
+
"Expected #{expectation}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def failure_message_for_should_not
|
20
|
+
"Did not expect #{expectation}"
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def collection?
|
26
|
+
@subject.send(:representable_attrs)[property].options[:collection] == true
|
27
|
+
end
|
28
|
+
|
29
|
+
def expectation
|
30
|
+
"#{@subject.class} to be a collection"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/matchers/version.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
1
|
require "matchers/class_name_matcher"
|
2
|
+
require "matchers/extension_of_matcher"
|
3
|
+
require "matchers/parse_strategy_matcher"
|
4
|
+
require "matchers/base_matcher"
|
2
5
|
require "matchers/representable_property_matcher"
|
3
|
-
require "matchers/
|
6
|
+
require "matchers/representable_collection_matcher"
|
7
|
+
require "matchers/have_representable_property_matcher"
|
8
|
+
require "matchers/have_representable_collection_matcher"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Representable::Matchers::BaseMatcher do
|
4
|
+
let(:property) { :foo }
|
5
|
+
let(:fake_matcher) { double("fake_matcher") }
|
6
|
+
let(:fake_representation) { double("fake_representation") }
|
7
|
+
|
8
|
+
subject { Representable::Matchers::BaseMatcher.new(property) }
|
9
|
+
|
10
|
+
describe "#matches?" do
|
11
|
+
it { expect( subject.matches?(fake_representation) ).to be_true }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#class_name" do
|
15
|
+
let(:class_name) { "Foo" }
|
16
|
+
|
17
|
+
it "adds a ClassNameMatcher" do
|
18
|
+
Representable::Matchers::ClassNameMatcher.should_receive(:new).with(property, class_name)
|
19
|
+
expect( subject.class_name(class_name) ).to eq(subject)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#extends" do
|
24
|
+
let(:extension) { Representable }
|
25
|
+
|
26
|
+
it "adds a ExtensionOfMatcher" do
|
27
|
+
Representable::Matchers::ExtensionOfMatcher.should_receive(:new).with(property, extension)
|
28
|
+
expect( subject.extends(extension) ).to eq(subject)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#description" do
|
33
|
+
it { expect( subject.description ).to be_a_kind_of(String) }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#failure_message_for_should" do
|
37
|
+
it { expect { subject.failure_message_for_should }.to raise_error }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#failure_message_for_should" do
|
41
|
+
it { expect { subject.failure_message_for_should_not }.to raise_error }
|
42
|
+
end
|
43
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Representable::Matchers::ClassNameMatcher do
|
4
|
+
it_should_behave_like "a matcher"
|
5
|
+
|
4
6
|
let(:property) { :foo }
|
5
7
|
let(:class_name) { "Person" }
|
6
8
|
|
@@ -28,10 +30,5 @@ describe Representable::Matchers::ClassNameMatcher do
|
|
28
30
|
expect( subject.matches?(subject_object) ).to be_false
|
29
31
|
end
|
30
32
|
end
|
31
|
-
|
32
33
|
end
|
33
|
-
|
34
|
-
its(:description) { should be_a_kind_of String }
|
35
|
-
its(:failure_message_for_should) { should be_a_kind_of String }
|
36
|
-
its(:failure_message_for_should_not) { should be_a_kind_of String }
|
37
34
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Representable::Matchers::ExtensionOfMatcher do
|
4
|
+
it_should_behave_like "a matcher"
|
5
|
+
|
6
|
+
let(:property) { :foo }
|
7
|
+
let(:extension) { Module }
|
8
|
+
|
9
|
+
subject { Representable::Matchers::ExtensionOfMatcher.new(property, extension) }
|
10
|
+
|
11
|
+
describe "#matches?" do
|
12
|
+
let(:fake_representation) { FakeRepresentable.representation }
|
13
|
+
|
14
|
+
context "when it matches" do
|
15
|
+
|
16
|
+
before do
|
17
|
+
fake_representation.stub_chain(:send, :[], :options, :[]).with(:extend).and_return(extension)
|
18
|
+
end
|
19
|
+
|
20
|
+
it do
|
21
|
+
expect( subject.matches?(fake_representation) ).to be_true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when it doesn't match" do
|
26
|
+
|
27
|
+
before do
|
28
|
+
fake_representation.stub_chain(:send, :[], :options, :[]).with(:extend).and_return(Representable)
|
29
|
+
end
|
30
|
+
|
31
|
+
it do
|
32
|
+
expect( subject.matches?(fake_representation) ).to be_false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Representable::Matchers do
|
4
|
+
subject { FakeRepresentable.representation }
|
5
|
+
|
6
|
+
describe "#have_representable_collection" do
|
7
|
+
context "without submatchers" do
|
8
|
+
it { should have_representable_collection(:children) }
|
9
|
+
end
|
10
|
+
|
11
|
+
context "with submatchers" do
|
12
|
+
it { should have_representable_collection(:children).class_name("Array").extends(AbstractRepresenter).parse_strategy(:sync) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Representable::Matchers::HaveRepresentableCollectionMatcher do
|
18
|
+
let(:property) { :foo }
|
19
|
+
let(:fake_matcher) { double("fake_matcher") }
|
20
|
+
let(:fake_representation) { double("fake_representation") }
|
21
|
+
|
22
|
+
subject { Representable::Matchers::HaveRepresentableCollectionMatcher.new(property) }
|
23
|
+
|
24
|
+
before do
|
25
|
+
Representable::Matchers::RepresentableCollectionMatcher.should_receive(:new).with(property).and_return(fake_matcher)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#parse_strategy" do
|
29
|
+
let(:parse_strategy) { :sync }
|
30
|
+
|
31
|
+
it "adds a ClassNameMatcher" do
|
32
|
+
Representable::Matchers::ParseStrategyMatcher.should_receive(:new).with(property, parse_strategy)
|
33
|
+
expect( subject.parse_strategy(parse_strategy) ).to eq(subject)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
its(:description) { should be_a_kind_of String }
|
38
|
+
end
|
@@ -1,16 +1,68 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
|
3
|
+
describe Representable::Matchers do
|
4
|
+
subject { FakeRepresentable.representation }
|
5
|
+
|
6
|
+
describe "#have_representable_property" do
|
7
|
+
context "without submatchers" do
|
8
|
+
it { should have_representable_property(:name) }
|
9
|
+
it { should_not have_representable_property(:foo) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with submatchers" do
|
13
|
+
it { should have_representable_property(:class_only).class_name("String") }
|
14
|
+
it { should have_representable_property(:class_and_extension).class_name("Array").extends(AbstractRepresenter) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
2
18
|
|
3
19
|
describe Representable::Matchers::HaveRepresentablePropertyMatcher do
|
4
|
-
|
20
|
+
let(:property) { :foo }
|
21
|
+
let(:fake_matcher) { double("fake_matcher") }
|
22
|
+
let(:fake_representation) { double("fake_representation") }
|
23
|
+
|
24
|
+
subject { Representable::Matchers::HaveRepresentablePropertyMatcher.new(property) }
|
25
|
+
|
26
|
+
before do
|
27
|
+
Representable::Matchers::RepresentablePropertyMatcher.should_receive(:new).with(property).and_return(fake_matcher)
|
28
|
+
fake_matcher.stub(:matches?).and_return(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#matches?" do
|
32
|
+
before do
|
33
|
+
fake_matcher.should_receive(:matches?).with(fake_representation).and_return(matches?)
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when it matches" do
|
37
|
+
let(:matches?) { true }
|
38
|
+
it { expect( subject.matches?(fake_representation) ).to be_true }
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when it doesn't match" do
|
42
|
+
let(:matches?) { false }
|
43
|
+
it { expect( subject.matches?(fake_representation) ).to be_false }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#class_name" do
|
48
|
+
let(:class_name) { "Foo" }
|
5
49
|
|
6
|
-
|
7
|
-
|
50
|
+
it "adds a ClassNameMatcher" do
|
51
|
+
Representable::Matchers::ClassNameMatcher.should_receive(:new).with(property, class_name)
|
52
|
+
expect( subject.class_name(class_name) ).to eq(subject)
|
53
|
+
end
|
54
|
+
end
|
8
55
|
|
9
|
-
describe "
|
56
|
+
describe "#extends" do
|
57
|
+
let(:extension) { Representable }
|
10
58
|
|
11
|
-
|
59
|
+
it "adds a ExtensionOfMatcher" do
|
60
|
+
Representable::Matchers::ExtensionOfMatcher.should_receive(:new).with(property, extension)
|
61
|
+
expect( subject.extends(extension) ).to eq(subject)
|
62
|
+
end
|
63
|
+
end
|
12
64
|
|
13
|
-
|
14
|
-
it {
|
65
|
+
describe "#description" do
|
66
|
+
it { expect( subject.description ).to be_a_kind_of String }
|
15
67
|
end
|
16
68
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Representable::Matchers::ParseStrategyMatcher do
|
4
|
+
it_should_behave_like "a matcher"
|
5
|
+
|
6
|
+
let(:property) { :foo }
|
7
|
+
let(:strategy) { :sync }
|
8
|
+
|
9
|
+
subject { Representable::Matchers::ParseStrategyMatcher.new(property, strategy) }
|
10
|
+
|
11
|
+
describe "#matches?" do
|
12
|
+
let(:parse_strategy) { :sync }
|
13
|
+
let(:fake_representation) { double("fake_representation") }
|
14
|
+
|
15
|
+
context "when it matches" do
|
16
|
+
before do
|
17
|
+
fake_representation.stub_chain(:send, :[], :options, :[]).with(:parse_strategy).and_return(parse_strategy)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "calls on the representable object for it's attributes" do
|
21
|
+
expect( subject.matches?(fake_representation) ).to be_true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when it doesn't match" do
|
26
|
+
before do
|
27
|
+
fake_representation.stub_chain(:send, :[], :options, :[], :to_s).and_return(:dont_sync)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "calls on the representable object for it's attributes" do
|
31
|
+
expect( subject.matches?(fake_representation) ).to be_false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Representable::Matchers::RepresentablePropertyMatcher do
|
4
|
+
it_should_behave_like "a matcher"
|
5
|
+
|
4
6
|
let(:property) { :foo }
|
5
7
|
subject { Representable::Matchers::RepresentablePropertyMatcher.new(property) }
|
6
8
|
|
@@ -27,8 +29,4 @@ describe Representable::Matchers::RepresentablePropertyMatcher do
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
30
|
-
|
31
|
-
its(:description) { should be_a_kind_of String }
|
32
|
-
its(:failure_message_for_should) { should be_a_kind_of String }
|
33
|
-
its(:failure_message_for_should_not) { should be_a_kind_of String }
|
34
32
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Representable::Matchers::RepresentableCollectionMatcher do
|
4
|
+
it_should_behave_like "a matcher"
|
5
|
+
|
6
|
+
let(:property) { :foo }
|
7
|
+
let(:collection) { true }
|
8
|
+
|
9
|
+
subject { Representable::Matchers::RepresentableCollectionMatcher.new(property) }
|
10
|
+
|
11
|
+
describe "#matches?" do
|
12
|
+
let(:fake_representation) { FakeRepresentable.representation }
|
13
|
+
|
14
|
+
context "when it matches" do
|
15
|
+
before do
|
16
|
+
fake_representation.stub_chain(:send, :[], :options, :[]).with(:collection).and_return(collection)
|
17
|
+
end
|
18
|
+
|
19
|
+
it do
|
20
|
+
expect( subject.matches?(fake_representation) ).to be_true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when it doesn't match" do
|
25
|
+
let(:collection) { false }
|
26
|
+
|
27
|
+
before do
|
28
|
+
fake_representation.stub_chain(:send, :[], :options, :[]).with(:collection).and_return(collection)
|
29
|
+
end
|
30
|
+
|
31
|
+
it do
|
32
|
+
expect( subject.matches?(fake_representation) ).to be_false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,9 +1,13 @@
|
|
1
|
+
module AbstractRepresenter
|
2
|
+
end
|
3
|
+
|
1
4
|
class FakeRepresentable
|
2
5
|
module Representer
|
3
6
|
include Representable::JSON
|
4
7
|
property :name
|
5
8
|
property :class_only, class: String
|
6
|
-
property :class_and_extension, class: Array
|
9
|
+
property :class_and_extension, class: Array, extend: AbstractRepresenter
|
10
|
+
collection :children, class: Array, extend: AbstractRepresenter, parse_strategy: :sync
|
7
11
|
end
|
8
12
|
|
9
13
|
def self.representation
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: representable_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Coding Zeal
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -80,19 +80,30 @@ files:
|
|
80
80
|
- LICENSE.txt
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
|
+
- lib/matchers/base_matcher.rb
|
83
84
|
- lib/matchers/class_name_matcher.rb
|
85
|
+
- lib/matchers/extension_of_matcher.rb
|
86
|
+
- lib/matchers/have_representable_collection_matcher.rb
|
84
87
|
- lib/matchers/have_representable_property_matcher.rb
|
88
|
+
- lib/matchers/parse_strategy_matcher.rb
|
89
|
+
- lib/matchers/representable_collection_matcher.rb
|
85
90
|
- lib/matchers/representable_property_matcher.rb
|
86
91
|
- lib/matchers/version.rb
|
87
92
|
- lib/representable_matchers.rb
|
88
93
|
- representable_matchers.gemspec
|
89
94
|
- spec/integrations/rspec.rb
|
90
95
|
- spec/integrations/test_unit.rb
|
96
|
+
- spec/matchers/base_matchers_spec.rb
|
91
97
|
- spec/matchers/class_name_matcher_spec.rb
|
98
|
+
- spec/matchers/extension_of_matcher_spec.rb
|
99
|
+
- spec/matchers/have_representable_collection_matcher_spec.rb
|
92
100
|
- spec/matchers/have_representable_property_matcher_spec.rb
|
101
|
+
- spec/matchers/parse_strategy_matcher_spec.rb
|
93
102
|
- spec/matchers/representable_attribute_matcher_spec.rb
|
103
|
+
- spec/matchers/representable_collection_matcher_spec.rb
|
94
104
|
- spec/spec_helper.rb
|
95
105
|
- spec/support/fake_representable.rb
|
106
|
+
- spec/support/shared_examples.rb
|
96
107
|
homepage: https://github.com/CodingZeal/representable_matchers
|
97
108
|
licenses:
|
98
109
|
- MIT
|
@@ -120,8 +131,14 @@ summary: Shoulda-style RSpec/Test Unit matchers for the Representable Gem
|
|
120
131
|
test_files:
|
121
132
|
- spec/integrations/rspec.rb
|
122
133
|
- spec/integrations/test_unit.rb
|
134
|
+
- spec/matchers/base_matchers_spec.rb
|
123
135
|
- spec/matchers/class_name_matcher_spec.rb
|
136
|
+
- spec/matchers/extension_of_matcher_spec.rb
|
137
|
+
- spec/matchers/have_representable_collection_matcher_spec.rb
|
124
138
|
- spec/matchers/have_representable_property_matcher_spec.rb
|
139
|
+
- spec/matchers/parse_strategy_matcher_spec.rb
|
125
140
|
- spec/matchers/representable_attribute_matcher_spec.rb
|
141
|
+
- spec/matchers/representable_collection_matcher_spec.rb
|
126
142
|
- spec/spec_helper.rb
|
127
143
|
- spec/support/fake_representable.rb
|
144
|
+
- spec/support/shared_examples.rb
|