rspec-rabl 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2811294d13480463ba3441a92c72ce976e17e64a
4
- data.tar.gz: bdbd8415e5fb173d4899720b83c1a8b97797fa0a
3
+ metadata.gz: 1299c683a49ba523e21bebe71e0c70792e51ebe4
4
+ data.tar.gz: 9ee575d9bc6b44c31ff377da249f3dc39a70047d
5
5
  SHA512:
6
- metadata.gz: 451dca70d53640adde76d2eb06fceb233f3edc88bc915594e804dd1db967d34600c709078ff320c75e5f3cc93fd5008370c661ff6a78d572df9ef8893e1467a7
7
- data.tar.gz: a3e97e32630e5fa644d46841719c1d31a01c2df0b29108a263daba2c5c160006d46a63dc286d3782de8611d99f00e9975b2176e429212b1fb07ee659e096a04a
6
+ metadata.gz: 861aff6cec7501bbd05c75e8c77a9fe4e65c009a5dbf4cd76bc5f59537ed87aeee1fa780b2bbb48125b2695277f7dee9f9c4ebf243f0a805074772980e6af06c
7
+ data.tar.gz: e1916ffd49d278989caf49df8b2fc220d51067862dc95304b5024b9633f1b7a405f17936944a36201156a9cce4ec77291d0b3081d06030763726ef523972b1d7
data/.travis.yml CHANGED
@@ -1,11 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9
4
- - 2.0
5
- - 2.1
6
- - 2.2
7
- - jruby-1.7
3
+ - 2.2.2
4
+ - ruby-head
8
5
  - jruby-9.0.4.0
6
+ - jruby-head
9
7
  before_install:
10
8
  - gem update --system
11
9
  - gem install bundler -v 1.10.6
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
@@ -14,6 +14,7 @@ module RSpec
14
14
  _rabl_template.gsub('.rabl',''),
15
15
  _rabl_data,
16
16
  :view_path => _rabl_config[:view_paths],
17
+ :scope => _rabl_config[:scope],
17
18
  )
18
19
  end
19
20
 
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Rabl
3
- VERSION = "2.0.0"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ object @user => :user
2
+ attributes :guid => :id
3
+ node(:full_name){ |user| full_name(user) }
4
+ node(:formatted_email){ |user| formatted_email(full_name(user), user.email) }
5
+ node(:password){ |user| hide_password(user.password) }
@@ -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
@@ -6,6 +6,7 @@ require 'rspec'
6
6
  require 'rspec/rabl'
7
7
 
8
8
  require 'support/user_context'
9
+ require 'support/renderer_scope_helper'
9
10
 
10
11
  RSpec.configure do |c|
11
12
  c.order = :rand
@@ -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.0.0
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-03-31 00:00:00.000000000 Z
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.5.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