rspec-rabl 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -5
- data/README.md +21 -0
- data/lib/rspec/rabl/example_group.rb +1 -0
- data/lib/rspec/rabl/version.rb +1 -1
- data/spec/fixtures/user_renderer_scope.rabl +5 -0
- data/spec/functional/renderer_scope_spec.rb +21 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/renderer_scope_helper.rb +13 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1299c683a49ba523e21bebe71e0c70792e51ebe4
|
4
|
+
data.tar.gz: 9ee575d9bc6b44c31ff377da249f3dc39a70047d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 861aff6cec7501bbd05c75e8c77a9fe4e65c009a5dbf4cd76bc5f59537ed87aeee1fa780b2bbb48125b2695277f7dee9f9c4ebf243f0a805074772980e6af06c
|
7
|
+
data.tar.gz: e1916ffd49d278989caf49df8b2fc220d51067862dc95304b5024b9633f1b7a405f17936944a36201156a9cce4ec77291d0b3081d06030763726ef523972b1d7
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -78,6 +78,27 @@ require 'rspec/rabl/rails'
|
|
78
78
|
|
79
79
|
For more detailed configuration just look at that file to see what configurations it is making.
|
80
80
|
|
81
|
+
Additionally, there are two config attributes which can be specified using `rabl_config`:
|
82
|
+
|
83
|
+
`scope` is the rendering context which is passed to create the underlying Rabl::Renderer instance for an example group. If your rabl template is using, for example, view helpers in Rails but your spec is raising a `NoMethodError`, then you probably want to pass in a scope which includes that helper.
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
describe "Users which use a Helper to transform data for presentation" do
|
87
|
+
class ScopeWithUsersHelper
|
88
|
+
include Singleton
|
89
|
+
include UsersHelper # could have a method which formats an email address for use below
|
90
|
+
end
|
91
|
+
|
92
|
+
rabl_config(:scope => ScopeWithUsersHelper.instance)
|
93
|
+
rabl_template { "users/show.rabl" }
|
94
|
+
rabl_data(:root => 'user') { user }
|
95
|
+
|
96
|
+
specify { expect(subject).to render_attribute(:formatted_email).with_value('"Kung Fury" <thechosenone@example.com>') }
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
`view_paths` instructs the Rabl::Renderer where to look for its rabl templates for the purpose of an example group.
|
101
|
+
|
81
102
|
## Contributing
|
82
103
|
|
83
104
|
1. Fork it
|
data/lib/rspec/rabl/version.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
describe "Renderer Scope" do
|
2
|
+
include_context "user_context"
|
3
|
+
|
4
|
+
describe "user_renderer_scope.rabl" do
|
5
|
+
rabl_data(:root => 'user'){ user }
|
6
|
+
rabl_config(scope: RendererScopeHelper)
|
7
|
+
|
8
|
+
it{ expect(subject).to render_attribute(:full_name).with_value('gob bluth') }
|
9
|
+
it{ expect(subject).to render_attribute(:formatted_email).with_value('"gob bluth" <gob@bluth.com>') }
|
10
|
+
it{ expect(subject).to render_attribute(:password).with_value('***********') }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "user_renderer_scope.rabl (without scope supplied)" do
|
14
|
+
rabl_data(:root => 'user'){ user }
|
15
|
+
rabl_template { "user_renderer_scope.rabl" }
|
16
|
+
|
17
|
+
it "should fail if not configured with an appropriate scope" do
|
18
|
+
expect{ rendered_template }.to raise_error(NoMethodError)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
class RendererScopeHelper
|
2
|
+
def self.full_name(user)
|
3
|
+
[user.first_name, user.last_name].join(" ")
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.formatted_email(name, email)
|
7
|
+
"\"#{name}\" <#{email}>"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.hide_password(password)
|
11
|
+
"*" * password.length
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-rabl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Ries
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,12 +109,15 @@ files:
|
|
109
109
|
- spec/fixtures/rootless_index.rabl
|
110
110
|
- spec/fixtures/user.rabl
|
111
111
|
- spec/fixtures/user_aliases.rabl
|
112
|
+
- spec/fixtures/user_renderer_scope.rabl
|
112
113
|
- spec/functional/custom_matchers_spec.rb
|
113
114
|
- spec/functional/matcher_errors_spec.rb
|
114
115
|
- spec/functional/render_object_spec.rb
|
116
|
+
- spec/functional/renderer_scope_spec.rb
|
115
117
|
- spec/functional/shared_examples_spec.rb
|
116
118
|
- spec/spec_helper.rb
|
117
119
|
- spec/support/full_name_renderer_examples.rb
|
120
|
+
- spec/support/renderer_scope_helper.rb
|
118
121
|
- spec/support/user_context.rb
|
119
122
|
homepage: https://github.com/mmmries/rspec_rabl
|
120
123
|
licenses:
|
@@ -136,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
139
|
version: '0'
|
137
140
|
requirements: []
|
138
141
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.6.6
|
140
143
|
signing_key:
|
141
144
|
specification_version: 4
|
142
145
|
summary: Provides a more declarative form of view testing for users of rabl
|
@@ -147,10 +150,13 @@ test_files:
|
|
147
150
|
- spec/fixtures/rootless_index.rabl
|
148
151
|
- spec/fixtures/user.rabl
|
149
152
|
- spec/fixtures/user_aliases.rabl
|
153
|
+
- spec/fixtures/user_renderer_scope.rabl
|
150
154
|
- spec/functional/custom_matchers_spec.rb
|
151
155
|
- spec/functional/matcher_errors_spec.rb
|
152
156
|
- spec/functional/render_object_spec.rb
|
157
|
+
- spec/functional/renderer_scope_spec.rb
|
153
158
|
- spec/functional/shared_examples_spec.rb
|
154
159
|
- spec/spec_helper.rb
|
155
160
|
- spec/support/full_name_renderer_examples.rb
|
161
|
+
- spec/support/renderer_scope_helper.rb
|
156
162
|
- spec/support/user_context.rb
|