representable_matchers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWRhZGE2NjQxZWMyM2NhYjk0NmU1ZWI3Njk1ZjQ1Mjc4ODRiNzQ1MQ==
5
+ data.tar.gz: !binary |-
6
+ ZjM3M2Q1NDM0ZTNkYTc2YzM1MmQxZTQ2ZDAyN2JhNjkwNzE1NzNlYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NTFkNmM2NTE2ZjQyYTcxNzQyYTRmMGExYjE0YTU2NjhjYTQwMDQzN2VhZDhi
10
+ MGJmYmU1ZDcwMmU0NDBlYjQ1Yzc2ZDQ5NjJiYmNlYjhmZTYwODY5N2JhMjkz
11
+ ZGMwZDcwOGM3Zjc2ODk2NGI4ZmE5NmEyOTY3NTE3ZTQ5YTg4YjE=
12
+ data.tar.gz: !binary |-
13
+ NjgzMGE2ZjgxZmIxYzFmNzAwYzM1ZDU1YjIxNmZlNDU5NTEyODY0MTkzNWFk
14
+ NGRmNDYwNTkxNTkwNjAwOTZlZWViM2IxZTQ5ZmJkNmVlYTEyN2ZhZjlhNWUy
15
+ MmFmMmUwNzg0NTFkNjJkY2I3ZDQ2MzhmYzRlNzc0Y2M1ZjdlYTg=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ matrix:
3
+ include:
4
+ - rvm: 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in representable_matchers.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Coding Zeal
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Representable Matchers
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)
4
+
5
+ Shoulda-style RSpec/Test Unit matchers for the Representable Gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'representable_matchers'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install representable_matchers
20
+
21
+ ## Usage
22
+
23
+ it { should have_representable_property(:name) }
24
+ it { should have_representable_collection(:children) }
25
+ it { should have_representable_hash(:preferences) }
26
+
27
+ With submatchers for addition options
28
+
29
+ it { should have_representable_property(:father).class_name("Person").extends(Person::Representer) }
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,34 @@
1
+ module Representable
2
+ module Matchers
3
+
4
+ class ClassNameMatcher < Struct.new(:property, :class_name)
5
+
6
+ def matches?(subject)
7
+ @subject = subject
8
+ matches_class?
9
+ end
10
+
11
+ def description
12
+ "only allow representable property of a specific class"
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_class?
26
+ @subject.send(:representable_attrs)[property].options[:class].to_s == class_name
27
+ end
28
+
29
+ def expectation
30
+ "#{@subject.class} to be a kind of #{class_name}"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,73 @@
1
+ module Representable
2
+ module Matchers
3
+
4
+ def have_representable_property(property)
5
+ HaveRepresentablePropertyMatcher.new(property)
6
+ end
7
+
8
+ class HaveRepresentablePropertyMatcher
9
+
10
+ def initialize(property)
11
+ @property = property
12
+ add_representable_property_submatcher
13
+ end
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
+ def description
31
+ # TODO
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
40
+ end
41
+
42
+ private
43
+
44
+ def add_representable_property_submatcher
45
+ add_submatcher(RepresentablePropertyMatcher.new(@property))
46
+ 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
+ end
72
+ end
73
+ end
@@ -0,0 +1,6 @@
1
+ # :enddoc:
2
+ require 'rspec/core'
3
+
4
+ RSpec.configure do |config|
5
+ config.include Representable::Matchers
6
+ end
@@ -0,0 +1,6 @@
1
+ if defined?(ActiveSupport::TestCase)
2
+ ActiveSupport::TestCase.class_eval do
3
+ include Representable::Matchers
4
+ extend Representable::Matchers
5
+ end
6
+ end
@@ -0,0 +1,34 @@
1
+ module Representable
2
+ module Matchers
3
+
4
+ class RepresentablePropertyMatcher < Struct.new(:property)
5
+
6
+ def matches?(subject)
7
+ @subject = subject
8
+ representable_attribute?
9
+ end
10
+
11
+ def description
12
+ "only allow models with specific representable properties"
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 representable_attribute?
26
+ !@subject.send(:representable_attrs)[property].nil?
27
+ end
28
+
29
+ def expectation
30
+ "#{@subject} to be a Representable property"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module RepresentableMatchers
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "matchers/version"
2
+ require "matchers/class_name_matcher"
3
+ require "matchers/extension_of_matcher"
4
+ require "matchers/representable_property_matcher"
5
+ require "matchers/have_representable_property_matcher"
6
+
7
+ # bind the matchers to the test mech
8
+ require 'matchers/integrations/rspec' if defined?(RSpec)
9
+ require 'matchers/integrations/test_unit'
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
3
+ require 'representable_matchers'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "representable_matchers"
7
+ spec.version = RepresentableMatchers::VERSION
8
+ spec.authors = ["Coding Zeal", "Adam Cuppy"]
9
+ spec.email = ["info@codingzeal.com"]
10
+ spec.description = %q{Shoulda-style RSpec/Test Unit matchers for the Representable Gem}
11
+ spec.summary = %q{Shoulda-style RSpec/Test Unit matchers for the Representable Gem}
12
+ spec.homepage = "https://github.com/CodingZeal/representable_matchers"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec", "~> 2.6.0"
23
+ spec.add_development_dependency "representable", "~> 1.7.3"
24
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe Representable::Matchers::HaveRepresentablePropertyMatcher do
4
+ subject { FakeRepresentable.representation }
5
+
6
+ it { should have_representable_property(:name) }
7
+ it { should_not have_representable_property(:foo) }
8
+
9
+ describe "submatchers" do
10
+
11
+ subject { FakeRepresentable.representation }
12
+
13
+ it { should have_representable_property(:class_only).class_name("String") }
14
+ it { should_not have_representable_property(:class_only).class_name("Foo") }
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ require 'rspec'
2
+ require 'rspec/autorun'
3
+ require 'representable'
4
+ require 'representable/json'
5
+ require 'representable_matchers'
6
+
7
+ PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
8
+ Dir[File.join(PROJECT_ROOT, 'spec/support/**/*.rb')].each { |file| require(file) }
9
+
10
+ RSpec.configure do |c|
11
+ c.filter_run_excluding :skip_on_windows => !(RbConfig::CONFIG['host_os'] =~ /mingw32/).nil?
12
+ end
@@ -0,0 +1,12 @@
1
+ class FakeRepresentable
2
+ module Representer
3
+ include Representable::JSON
4
+ property :name
5
+ property :class_only, class: String
6
+ property :class_and_extension, class: Array
7
+ end
8
+
9
+ def self.representation
10
+ new.extend(Representer)
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: representable_matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Coding Zeal
8
+ - Adam Cuppy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: 2.6.0
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 2.6.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: representable
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 1.7.3
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.7.3
70
+ description: Shoulda-style RSpec/Test Unit matchers for the Representable Gem
71
+ email:
72
+ - info@codingzeal.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .travis.yml
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/matchers/class_name_matcher.rb
84
+ - lib/matchers/have_representable_property_matcher.rb
85
+ - lib/matchers/integrations/rspec.rb
86
+ - lib/matchers/integrations/test_unit.rb
87
+ - lib/matchers/representable_property_matcher.rb
88
+ - lib/matchers/version.rb
89
+ - lib/representable_matchers.rb
90
+ - representable_matchers.gemspec
91
+ - spec/matchers/have_representable_property_matcher_spec.rb
92
+ - spec/spec_helper.rb
93
+ - spec/support/fake_representable.rb
94
+ homepage: https://github.com/CodingZeal/representable_matchers
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.1.11
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Shoulda-style RSpec/Test Unit matchers for the Representable Gem
118
+ test_files:
119
+ - spec/matchers/have_representable_property_matcher_spec.rb
120
+ - spec/spec_helper.rb
121
+ - spec/support/fake_representable.rb