rspec-rabl 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53940a4a41092ab090cda50e3b4aa9c7c5e34b60
4
- data.tar.gz: 4e50171150a0e9819439e807f8ef3361131b5512
3
+ metadata.gz: 2811294d13480463ba3441a92c72ce976e17e64a
4
+ data.tar.gz: bdbd8415e5fb173d4899720b83c1a8b97797fa0a
5
5
  SHA512:
6
- metadata.gz: 51e74dad39d51f02879c2f4a6cecc438b630971596009f4cee8fc901ff445c01f457595b1b2f7309a842c29318a9f4788c6306be4392f69f650fab355fd009e3
7
- data.tar.gz: f5322992ad11e2bd1d567698f9e8d50bea8c5af592698a07b1319a4087502f0586db780600bf24f9829402f80b9b1151bcd7253aec05f784b74477cae761aea3
6
+ metadata.gz: 451dca70d53640adde76d2eb06fceb233f3edc88bc915594e804dd1db967d34600c709078ff320c75e5f3cc93fd5008370c661ff6a78d572df9ef8893e1467a7
7
+ data.tar.gz: a3e97e32630e5fa644d46841719c1d31a01c2df0b29108a263daba2c5c160006d46a63dc286d3782de8611d99f00e9975b2176e429212b1fb07ee659e096a04a
@@ -11,12 +11,21 @@ module RSpec
11
11
  end
12
12
 
13
13
  def failure_message
14
- "expected #{expected_value.inspect} in #{attribute_path}\n got #{rendered_value.inspect}"
14
+ if implicit_nil_value?
15
+ "nil value when testing.\n expected #{expected_value.inspect} in #{attribute_path}\n got #{rendered_value.inspect}\n If you want to test for a nil value, please use `with_value(nil)`"
16
+ else
17
+ "expected #{expected_value.inspect} in #{attribute_path}\n got #{rendered_value.inspect}"
18
+ end
15
19
  end
16
20
 
17
21
  def matches?(subject)
18
22
  @subject = subject
19
- attribute_rendered? && (!expected_value_set || rendered_value == expected_value)
23
+ attribute_rendered? && (!expected_value_set || rendered_value == expected_value) && !implicit_nil_value?
24
+ end
25
+
26
+ def implicit_nil_value?
27
+ return false if expected_value_set
28
+ rendered_value.nil? || expected_value.nil?
20
29
  end
21
30
 
22
31
  def with(model_attribute)
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Rabl
3
- VERSION = "1.1.1"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -45,4 +45,23 @@ describe "Error Messages" do
45
45
  expect(lines).to include(" expected \"Imma derp derp\" in [\"users\"][\"user\"][\"guid\"]")
46
46
  expect(lines).to include(" got \"abc\"")
47
47
  end
48
+
49
+ it "renders a helpful error message for nil tests" do
50
+ example = nil
51
+ group = RSpec.describe "index.rabl" do
52
+ include_context "user_context"
53
+ rabl_data(:root => "users", :object_root => "user"){ [user] }
54
+ example = it "tries to render nil attribute" do
55
+ allow(user).to receive(:foo).and_return(nil)
56
+ expect(subject).to render_attribute(:foo)
57
+ end
58
+ end
59
+ group.run
60
+ lines = RSpec::Core::Notifications::FailedExampleNotification.new(example).message_lines.join("\n")
61
+
62
+ expect(lines).to include("nil value when testing.")
63
+ expect(lines).to include(" expected nil in [\"users\"][\"user\"][\"foo\"]")
64
+ expect(lines).to include(" got nil")
65
+ expect(lines).to include(" If you want to test for a nil value, please use `with_value(nil)`")
66
+ end
48
67
  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: 1.1.1
4
+ version: 2.0.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-01-21 00:00:00.000000000 Z
11
+ date: 2016-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
- rubygems_version: 2.5.1
139
+ rubygems_version: 2.5.2
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Provides a more declarative form of view testing for users of rabl