grape-juice 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 562a3468b3300d849951665338c975130a5db9c2
4
+ data.tar.gz: 60940ebfa1a1cefbfdbc08cd7e9b378db0c25efe
5
+ SHA512:
6
+ metadata.gz: e8af2fedbbf3c05901cd659ffb4b74004f3b329b358d60aca3739f3a47a7e5a0490658bb5cae6b984008c1221d419e6baba683255d8f77252fbd923ce457edfb
7
+ data.tar.gz: e09f27e11a44e94907038840287354f56abee3e0bfd355eb32ad91186623939fc679762fe417e819b98abf38003f5c73ce58bfd34457f32570696efcee237f17
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grape-juice.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 HalfTime
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Nick DeLuca
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.
@@ -0,0 +1,31 @@
1
+ # Grape::Juice
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'grape-juice'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install grape-juice
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/grape-juice/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grape_juice/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "grape-juice"
8
+ spec.version = GrapeJuice::VERSION
9
+ spec.authors = ["Nick DeLuca"]
10
+ spec.email = ["nickdeluca08@gmail.com"]
11
+ spec.summary = %q{Rspec matchers for grape-entity}
12
+ spec.description = %q{Rspec matchers for grape-entity}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "grape-entity"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", ">=3.0.0"
26
+ end
@@ -0,0 +1 @@
1
+ require 'grape_juice'
@@ -0,0 +1,7 @@
1
+ require 'grape_juice/expose_matcher'
2
+ require 'grape_juice/integration'
3
+ require 'grape_juice/version'
4
+
5
+ module GrapeJuice
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,159 @@
1
+ module GrapeJuice
2
+ module ExposeMatcher
3
+
4
+ def expose(exposure)
5
+ ExposeMatcher.new(exposure)
6
+ end
7
+
8
+ class ExposeMatcher
9
+
10
+ def initialize(exposure)
11
+ @expected_exposure = exposure
12
+ end
13
+
14
+ def matches?(subject)
15
+ @subject = subject
16
+
17
+ verify_entity &&
18
+ exposure_correct? &&
19
+ as_correct? &&
20
+ if_conditions_correct? &&
21
+ unless_conditions_correct? &&
22
+ format_correct? &&
23
+ safe_correct?
24
+ end
25
+
26
+ def as(exposure_name)
27
+ @as_exposure = exposure_name
28
+ self
29
+ end
30
+
31
+ def if(conditions)
32
+ @if_conditions = conditions
33
+ self
34
+ end
35
+
36
+ def unless(conditions)
37
+ @unless_conditions = conditions
38
+ self
39
+ end
40
+
41
+ def using(other_entity)
42
+ @using_entity = other_entity
43
+ self
44
+ end
45
+
46
+ def format_with(formatter)
47
+ @formatter = formatter
48
+ self
49
+ end
50
+
51
+ def safe(value)
52
+ @safe = !!value
53
+ self
54
+ end
55
+
56
+ def failure_message
57
+ @failure_message
58
+ end
59
+
60
+ def failure_message_when_negated
61
+ @negated_failure_message
62
+ end
63
+
64
+ def description
65
+ "Tests the expose method for kinds of Grape::Entity."
66
+ end
67
+
68
+ private
69
+
70
+ def representee
71
+ end
72
+
73
+ def exposure
74
+ entity.exposures[@expected_exposure]
75
+ end
76
+
77
+ def entity
78
+ @subject.respond_to?(:new) ? @subject.new(representee) : @subject
79
+ rescue ArgumentError
80
+ end
81
+
82
+ def verify_entity
83
+ if !entity.kind_of?(Grape::Entity)
84
+ @failure_message = "#{@subject} is not a kind of Grape::Entity"
85
+ @negated_failure_message = "#{@subject} is not a kind of Grape::Entity"
86
+ false
87
+ else
88
+ true
89
+ end
90
+ end
91
+
92
+ def exposure_correct?
93
+ if exposure.nil?
94
+ @failure_message = "#{@subject} does not expose #{@expected_exposure}"
95
+ false
96
+ else
97
+ @negated_failure_message = "#{@subject} exposes #{@expected_exposure} when it should not"
98
+ true
99
+ end
100
+ end
101
+
102
+ def as_correct?
103
+ return true if @as_exposure.nil?
104
+
105
+ if @as_exposure != exposure[:as]
106
+ @failure_message = "#{@subject} does not expose #{@expected_exposure} as #{@as_exposure}"
107
+ false
108
+ else
109
+ true
110
+ end
111
+ end
112
+
113
+ def if_conditions_correct?
114
+ return true if @if_conditions.nil?
115
+
116
+ if exposure[:if] != @if_conditions
117
+ @failure_message = "Expected if condition #{@if_conditions}, got #{exposure[:if] || 'nil'}"
118
+ false
119
+ else
120
+ true
121
+ end
122
+ end
123
+
124
+ def unless_conditions_correct?
125
+ return true if @unless_conditions.nil?
126
+
127
+ if exposure[:unless] != @unless_conditions
128
+ @failure_message = "Expected unless condition #{@unless_conditions}, got #{exposure[:unless] || 'nil'}"
129
+ false
130
+ else
131
+ true
132
+ end
133
+ end
134
+
135
+ def format_correct?
136
+ return true if @formatter.nil?
137
+
138
+ if exposure[:format_with] != @formatter
139
+ @failure_message = "Expected #{@expected_exposure} to be formatted with #{@formatter}, but got #{exposure[:format_with]}"
140
+ false
141
+ else
142
+ true
143
+ end
144
+ end
145
+
146
+ def safe_correct?
147
+ return true if @safe.nil?
148
+
149
+ if @safe && @safe != exposure[:safe]
150
+ @failure_message = "Expected safe to be #{@safe}, but got #{exposure[:safe] || 'nil'}"
151
+ false
152
+ else
153
+ true
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
159
+
@@ -0,0 +1,12 @@
1
+ require 'grape_juice/expose_matcher'
2
+ require 'grape_juice/integration/rspec'
3
+
4
+ module GrapeJuice
5
+ module Integration
6
+
7
+ if defined?(Rspec)
8
+ require 'grape_juice/integration/rspec'
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module GrapeJuice
2
+ module Integration
3
+ module Rspec
4
+
5
+ RSpec.configure do |config|
6
+ config.include GrapeJuice::ExposeMatcher
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module GrapeJuice
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe GrapeJuice::ExposeMatcher do
4
+
5
+ context "rspec integration" do
6
+ class PersonEntity < Grape::Entity
7
+ expose :name
8
+ end
9
+
10
+ subject { PersonEntity }
11
+
12
+
13
+ it { is_expected.to expose(:name) }
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'grape-entity'
5
+ require 'grape-juice' # and any other gems you need
6
+
7
+ RSpec.configure do |config|
8
+ # some (optional) config here
9
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grape-juice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nick DeLuca
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grape-entity
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.0
69
+ description: Rspec matchers for grape-entity
70
+ email:
71
+ - nickdeluca08@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - grape-juice.gemspec
83
+ - lib/grape-juice.rb
84
+ - lib/grape_juice.rb
85
+ - lib/grape_juice/expose_matcher.rb
86
+ - lib/grape_juice/integration.rb
87
+ - lib/grape_juice/integration/rspec.rb
88
+ - lib/grape_juice/version.rb
89
+ - spec/grape_juice/expose_matcher_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: ''
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Rspec matchers for grape-entity
115
+ test_files:
116
+ - spec/grape_juice/expose_matcher_spec.rb
117
+ - spec/spec_helper.rb
118
+ has_rdoc: