rspec_rabl 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/rspec/rabl/attribute_matcher.rb +88 -0
- data/lib/rspec/rabl/example_group.rb +42 -0
- data/lib/rspec/rabl/helpers.rb +22 -0
- data/lib/rspec/rabl/matchers.rb +9 -0
- data/lib/rspec_rabl/version.rb +3 -0
- data/lib/rspec_rabl.rb +16 -0
- data/rspec_rabl.gemspec +26 -0
- data/spec/fixtures/bare_index.rabl +2 -0
- data/spec/fixtures/index.rabl +2 -0
- data/spec/fixtures/nested/test.rabl +2 -0
- data/spec/fixtures/rootless_index.rabl +2 -0
- data/spec/fixtures/user.rabl +5 -0
- data/spec/fixtures/user_aliases.rabl +3 -0
- data/spec/functional/custom_matchers_spec.rb +46 -0
- data/spec/functional/render_object_spec.rb +31 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/user_context.rb +9 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 263b3693c358ca3ade3ab55ea65c1861a031e8e0
|
4
|
+
data.tar.gz: ede0d8c7156530750705d6c4f3480f1c17aa53ae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb56108c0cf158ae0aa67c7f2ab1431352af722f7e41444cc076b7c50bde014fbe6b178a1f5aa7a4b3ffd50d37344783dc0dbe055322451153e8d0dad194e4fc
|
7
|
+
data.tar.gz: 46e3d5ad6f59b213b38e5fc3ba1c81f6e66598a01ef72b626215952593b2a1822deeeb40e311d311545a94afbffbab6fdcab5917443961d1ac958e1c4c20dd70
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Michael Ries
|
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,29 @@
|
|
1
|
+
# RspecRabl
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rspec_rabl'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rspec_rabl
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Rabl
|
3
|
+
class AttributeMatcher
|
4
|
+
def initialize(rendered_attribute, opts = {})
|
5
|
+
@rendered_attribute = rendered_attribute
|
6
|
+
@opts = opts
|
7
|
+
end
|
8
|
+
|
9
|
+
def description
|
10
|
+
"render the #{rendered_attribute} attribute"
|
11
|
+
end
|
12
|
+
|
13
|
+
def failure_message
|
14
|
+
"expected #{parsed} to render #{rendered_attribute} = #{expected_value}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def matches?(subject)
|
18
|
+
@subject = subject
|
19
|
+
attribute_rendered? && rendered_value == expected_value
|
20
|
+
end
|
21
|
+
|
22
|
+
def with(model_attribute)
|
23
|
+
@model_attribute = model_attribute
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def with_value(expected_value)
|
28
|
+
@expected_value = expected_value
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
attr_reader :rendered_attribute, :subject, :opts
|
34
|
+
|
35
|
+
def model_attribute
|
36
|
+
@model_attribute ||= rendered_attribute
|
37
|
+
end
|
38
|
+
|
39
|
+
def expected_value
|
40
|
+
@expected_value ||= get_attribute_from_rendered_object
|
41
|
+
end
|
42
|
+
|
43
|
+
def rendered_value
|
44
|
+
parsed_object[rendered_attribute.to_s]
|
45
|
+
end
|
46
|
+
|
47
|
+
def rendered_object
|
48
|
+
subject.object
|
49
|
+
end
|
50
|
+
|
51
|
+
def attribute_rendered?
|
52
|
+
parsed_object.has_key?(rendered_attribute.to_s)
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_attribute_from_rendered_object
|
56
|
+
if collection?
|
57
|
+
rendered_object.first.public_send(model_attribute)
|
58
|
+
else
|
59
|
+
rendered_object.public_send(model_attribute)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def collection?
|
64
|
+
rendered_object.is_a?(Array)
|
65
|
+
end
|
66
|
+
|
67
|
+
def parsed_object
|
68
|
+
collection? ? parse_collection_object : parse_object
|
69
|
+
end
|
70
|
+
|
71
|
+
def parse_collection_object
|
72
|
+
data = parsed
|
73
|
+
data = data[opts[:root]] if opts[:root]
|
74
|
+
data = data.first
|
75
|
+
data = data[opts[:object_root]] if opts[:object_root]
|
76
|
+
data
|
77
|
+
end
|
78
|
+
|
79
|
+
def parse_object
|
80
|
+
opts[:root] ? parsed[opts[:root]] : parsed
|
81
|
+
end
|
82
|
+
|
83
|
+
def parsed
|
84
|
+
@parsed ||= JSON.parse(subject.render)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Rabl
|
3
|
+
module ExampleGroup
|
4
|
+
def parsed_json
|
5
|
+
JSON.parse(rendered_template)
|
6
|
+
end
|
7
|
+
|
8
|
+
def rendered_template
|
9
|
+
renderer.render
|
10
|
+
end
|
11
|
+
|
12
|
+
def renderer
|
13
|
+
@renderer ||= ::Rabl::Renderer.new(
|
14
|
+
_rabl_template.gsub('.rabl',''),
|
15
|
+
_rabl_data,
|
16
|
+
:view_path => _rabl_config[:view_paths],
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def subject
|
21
|
+
renderer
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def _rabl_config
|
26
|
+
RSpec.configuration.rabl_configuration
|
27
|
+
end
|
28
|
+
|
29
|
+
def _rabl_data
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def _rabl_opts
|
34
|
+
{}
|
35
|
+
end
|
36
|
+
|
37
|
+
def _rabl_template
|
38
|
+
example.metadata[:example_group][:description]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Rabl
|
3
|
+
module Helpers
|
4
|
+
def rabl_data(opts = {},&block)
|
5
|
+
let(:_rabl_opts){ opts }
|
6
|
+
let(:_rabl_data, &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
def rabl_template(&block)
|
10
|
+
let(:_rabl_template, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def view_path(relative_path)
|
14
|
+
let(:_view_path) { relative_path }
|
15
|
+
end
|
16
|
+
|
17
|
+
def rabl_config(local_config)
|
18
|
+
let(:_rabl_config) { RSpec.configuration.rabl_configuration.merge(local_config) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/rspec_rabl.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require "rspec_rabl/version"
|
3
|
+
|
4
|
+
# helpers to access the rendered template and parsed template
|
5
|
+
require 'rspec/rabl/example_group'
|
6
|
+
# helpers that can be called outside an it block to configure data and settings
|
7
|
+
require 'rspec/rabl/helpers'
|
8
|
+
# custom matchers
|
9
|
+
require 'rspec/rabl/attribute_matcher'
|
10
|
+
# helpers for invoking the custom matchers
|
11
|
+
require 'rspec/rabl/matchers'
|
12
|
+
|
13
|
+
RSpec.configure do |c|
|
14
|
+
c.add_setting :rabl_configuration
|
15
|
+
c.include RSpec::Rabl::Matchers
|
16
|
+
end
|
data/rspec_rabl.gemspec
ADDED
@@ -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 'rspec_rabl/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec_rabl"
|
8
|
+
spec.version = RspecRabl::VERSION
|
9
|
+
spec.authors = ["Michael Ries"]
|
10
|
+
spec.email = ["michael@riesd.com"]
|
11
|
+
spec.description = "Provides a more declarative form of view testing for users of rabl"
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "pry-nav"
|
24
|
+
spec.add_runtime_dependency "rspec" , "~> 2.14"
|
25
|
+
spec.add_runtime_dependency "rabl", "~> 0.9"
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Customer Matchers" do
|
4
|
+
include_context "user_context"
|
5
|
+
|
6
|
+
describe "user.rabl" do
|
7
|
+
rabl_data(:root => 'user'){ user }
|
8
|
+
it{ should render(:guid) }
|
9
|
+
it{ should render(:first_name) }
|
10
|
+
it{ should render(:last_name) }
|
11
|
+
it{ should render(:email) }
|
12
|
+
it{ should_not render(:password) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "user_aliases.rabl" do
|
16
|
+
rabl_data(:root => 'user'){ user }
|
17
|
+
it{ should render(:id).with(:guid) }
|
18
|
+
it{ should render(:team).with_value('Gorby Puff') }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "index.rabl" do
|
22
|
+
rabl_data(:root => 'users', :object_root => 'user'){ [user] }
|
23
|
+
it{ should render(:guid) }
|
24
|
+
it{ should render(:first_name) }
|
25
|
+
it{ should render(:last_name) }
|
26
|
+
it{ should render(:email) }
|
27
|
+
it{ should_not render(:password) }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "rootless_index.rabl" do
|
31
|
+
rabl_data(:root => false, :object_root => 'user'){ [user] }
|
32
|
+
it{ should render(:guid) }
|
33
|
+
it{ should_not render(:password) }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "bare_index.rabl" do
|
37
|
+
rabl_data(:root => false, :object_root => false){ [user] }
|
38
|
+
it{ should render(:guid) }
|
39
|
+
it{ should_not render(:password) }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "nested/test.rabl" do
|
43
|
+
rabl_data(:root => 'test'){ user }
|
44
|
+
it{ should render(:guid) }
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "User Views" do
|
4
|
+
include_context "user_context"
|
5
|
+
rabl_data{ user }
|
6
|
+
|
7
|
+
describe "user.rabl" do
|
8
|
+
it "should make the rendered template available" do
|
9
|
+
rendered_template.should == '{"user":{"guid":"abc","first_name":"gob","last_name":"bluth","email":"gob@bluth.com"}}'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should make the parsed template available" do
|
13
|
+
parsed_json.should == {
|
14
|
+
'user' => {
|
15
|
+
'guid' => user.guid,
|
16
|
+
'first_name' => user.first_name,
|
17
|
+
'last_name' => user.last_name,
|
18
|
+
'email' => user.email,
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "test.rabl" do
|
25
|
+
rabl_config( {:view_paths => 'spec/fixtures/nested'} )
|
26
|
+
|
27
|
+
it "should allow us to override the Rabl config" do
|
28
|
+
parsed_json.should == {'test' => {'guid' => user.guid}}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'json'
|
3
|
+
require 'pry-nav'
|
4
|
+
require 'rabl'
|
5
|
+
require 'rspec'
|
6
|
+
require 'rspec_rabl'
|
7
|
+
|
8
|
+
require 'support/user_context'
|
9
|
+
|
10
|
+
RSpec.configure do |c|
|
11
|
+
c.order = :rand
|
12
|
+
c.color = :true
|
13
|
+
c.include RSpec::Rabl::ExampleGroup
|
14
|
+
c.rabl_configuration = {:view_paths => 'spec/fixtures'}
|
15
|
+
end
|
16
|
+
|
17
|
+
include RSpec::Rabl::Helpers
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec_rabl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Ries
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-nav
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '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: '2.14'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rabl
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
83
|
+
description: Provides a more declarative form of view testing for users of rabl
|
84
|
+
email:
|
85
|
+
- michael@riesd.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/rspec/rabl/attribute_matcher.rb
|
96
|
+
- lib/rspec/rabl/example_group.rb
|
97
|
+
- lib/rspec/rabl/helpers.rb
|
98
|
+
- lib/rspec/rabl/matchers.rb
|
99
|
+
- lib/rspec_rabl.rb
|
100
|
+
- lib/rspec_rabl/version.rb
|
101
|
+
- rspec_rabl.gemspec
|
102
|
+
- spec/fixtures/bare_index.rabl
|
103
|
+
- spec/fixtures/index.rabl
|
104
|
+
- spec/fixtures/nested/test.rabl
|
105
|
+
- spec/fixtures/rootless_index.rabl
|
106
|
+
- spec/fixtures/user.rabl
|
107
|
+
- spec/fixtures/user_aliases.rabl
|
108
|
+
- spec/functional/custom_matchers_spec.rb
|
109
|
+
- spec/functional/render_object_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
- spec/support/user_context.rb
|
112
|
+
homepage: ''
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.1.11
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Provides a more declarative form of view testing for users of rabl
|
136
|
+
test_files:
|
137
|
+
- spec/fixtures/bare_index.rabl
|
138
|
+
- spec/fixtures/index.rabl
|
139
|
+
- spec/fixtures/nested/test.rabl
|
140
|
+
- spec/fixtures/rootless_index.rabl
|
141
|
+
- spec/fixtures/user.rabl
|
142
|
+
- spec/fixtures/user_aliases.rabl
|
143
|
+
- spec/functional/custom_matchers_spec.rb
|
144
|
+
- spec/functional/render_object_spec.rb
|
145
|
+
- spec/spec_helper.rb
|
146
|
+
- spec/support/user_context.rb
|