rspec-its 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -5
- data/Changelog.md +7 -1
- data/Gemfile +4 -6
- data/README.md +1 -1
- data/features/its.feature +13 -0
- data/lib/rspec/its.rb +5 -2
- data/lib/rspec/its/version.rb +1 -1
- data/spec/rspec/its_spec.rb +141 -132
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4627e0d122f6f6d60961135154b6068ff823fa63
|
4
|
+
data.tar.gz: 245f30f1298a86c8da41930d50bef0f01bee090c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47f4f6c32e9df24cfc6710fe5c96e81d82b5dcb3e4ee487065e20809e27ca64b7bf64a7516ef80bf82b74c6d113f3950a80aec890f410277f29df7530911b88a
|
7
|
+
data.tar.gz: d8716722becc4400ae94f15ef310336e52cedcd2cb4041de1f9c3fe22904121e23e3cbceb9ff3b6323eab48e7992f03c95a1c45a55a4de395dcee262b63011b8
|
data/.travis.yml
CHANGED
@@ -5,16 +5,16 @@ rvm:
|
|
5
5
|
- 1.8.7
|
6
6
|
- 1.9.2
|
7
7
|
- 1.9.3
|
8
|
+
- 2.0.0
|
9
|
+
- 2.1.0
|
8
10
|
- ree
|
9
11
|
- jruby-18mode
|
10
|
-
- jruby
|
12
|
+
- jruby
|
11
13
|
- rbx
|
12
|
-
- 2.0.0
|
13
|
-
- 2.1.0
|
14
14
|
env:
|
15
15
|
- BRANCH=master
|
16
16
|
- BRANCH=2-99-maintenance
|
17
17
|
matrix:
|
18
18
|
allow_failures:
|
19
|
-
- rvm:
|
20
|
-
|
19
|
+
- rvm: jruby-18mode
|
20
|
+
|
data/Changelog.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
+
### 1.0.1 / 2014-04-13
|
2
|
+
[full changelog](http://github.com/rspec/rspec-its/compare/v1.0.0...v1.0.1)
|
3
|
+
|
4
|
+
Bug fixes:
|
5
|
+
* Maintain implicit subject in all cases (addresses problem with latest RSpec 3 version)
|
6
|
+
|
1
7
|
### 1.0.0 / 2014-02-07
|
2
|
-
[full changelog](http://github.com/rspec/rspec-its/compare/v1.0.0.pre...
|
8
|
+
[full changelog](http://github.com/rspec/rspec-its/compare/v1.0.0.pre...v1.0.0)
|
3
9
|
|
4
10
|
Breaking Changes:
|
5
11
|
|
data/Gemfile
CHANGED
@@ -3,20 +3,18 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in rspec-its.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
%w[rspec rspec-core rspec-expectations rspec-mocks].each do |lib|
|
6
|
+
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
|
7
|
+
branch = ENV.fetch('BRANCH','master')
|
8
|
+
next if branch == '2-99-maintenance' && lib == 'rspec-support'
|
7
9
|
library_path = File.expand_path("../../#{lib}", __FILE__)
|
8
10
|
if File.exist?(library_path)
|
9
11
|
gem lib, :path => library_path
|
10
12
|
else
|
11
13
|
gem lib, :git => "git://github.com/rspec/#{lib}.git",
|
12
|
-
:branch =>
|
14
|
+
:branch => branch
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
|
-
# only pull rspec-support from master
|
17
|
-
|
18
|
-
gem "rspec-support", :git => "git://github.com/rspec/rspec-support.git"
|
19
|
-
|
20
18
|
# test coverage
|
21
19
|
# gem 'simplecov', :require => false
|
22
20
|
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
Use the `its` method
|
21
|
+
Use the `its` method to generate a nested example group with
|
22
22
|
a single example that specifies the expected value of an attribute of the
|
23
23
|
subject using `should`, `should_not` or `is_expected`.
|
24
24
|
|
data/features/its.feature
CHANGED
@@ -83,3 +83,16 @@ Feature: attribute of subject
|
|
83
83
|
"""
|
84
84
|
When I run rspec
|
85
85
|
Then the examples should all pass
|
86
|
+
|
87
|
+
Scenario: failures are correctly reported as coming from the `its` line
|
88
|
+
Given a file named "example_spec.rb" with:
|
89
|
+
"""ruby
|
90
|
+
describe Array do
|
91
|
+
context "when first created" do
|
92
|
+
its(:size) { should_not eq(0) }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
"""
|
96
|
+
When I run rspec
|
97
|
+
Then the output should contain "Failure/Error: its(:size) { should_not eq(0) }"
|
98
|
+
And the output should not match /#[^\n]*rspec[\x2f]its/
|
data/lib/rspec/its.rb
CHANGED
@@ -79,7 +79,7 @@ module RSpec
|
|
79
79
|
# its(:age) { should eq(25) }
|
80
80
|
# end
|
81
81
|
def its(attribute, &block)
|
82
|
-
describe(attribute) do
|
82
|
+
describe(attribute.to_s) do
|
83
83
|
if Array === attribute
|
84
84
|
let(:__its_subject) { subject[*attribute] }
|
85
85
|
else
|
@@ -103,7 +103,9 @@ module RSpec
|
|
103
103
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(__its_subject, matcher, message)
|
104
104
|
end
|
105
105
|
|
106
|
-
|
106
|
+
its_caller = caller.select {|file_line| file_line !~ %r(/lib/rspec/its) }
|
107
|
+
example(nil, :caller => its_caller, &block)
|
108
|
+
|
107
109
|
end
|
108
110
|
end
|
109
111
|
|
@@ -112,6 +114,7 @@ end
|
|
112
114
|
|
113
115
|
RSpec.configure do |rspec|
|
114
116
|
rspec.extend RSpec::Its
|
117
|
+
rspec.backtrace_exclusion_patterns << %r(/lib/rspec/its)
|
115
118
|
end
|
116
119
|
|
117
120
|
RSpec::SharedContext.send(:include, RSpec::Its)
|
data/lib/rspec/its/version.rb
CHANGED
data/spec/rspec/its_spec.rb
CHANGED
@@ -3,179 +3,188 @@ require 'spec_helper'
|
|
3
3
|
module RSpec
|
4
4
|
describe Its do
|
5
5
|
describe "#its" do
|
6
|
-
subject do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def call_count
|
13
|
-
@call_count += 1
|
14
|
-
end
|
15
|
-
end.new
|
16
|
-
end
|
17
|
-
|
18
|
-
context "with a call counter" do
|
19
|
-
its(:call_count) { should eq(1) }
|
6
|
+
context "with implicit subject" do
|
7
|
+
context "preserves described_class" do
|
8
|
+
its(:symbol) { expect(described_class).to be Its}
|
9
|
+
its([]) { expect(described_class).to be Its }
|
10
|
+
end
|
20
11
|
end
|
21
|
-
|
22
|
-
context "with nil value" do
|
12
|
+
context "with explicit subject" do
|
23
13
|
subject do
|
24
14
|
Class.new do
|
25
|
-
def
|
26
|
-
|
15
|
+
def initialize
|
16
|
+
@call_count = 0
|
27
17
|
end
|
28
|
-
end.new
|
29
|
-
end
|
30
|
-
its(:nil_value) { should be_nil }
|
31
|
-
end
|
32
18
|
|
33
|
-
|
34
|
-
|
35
|
-
Class.new do
|
36
|
-
def name
|
37
|
-
"John"
|
19
|
+
def call_count
|
20
|
+
@call_count += 1
|
38
21
|
end
|
39
22
|
end.new
|
40
23
|
end
|
41
|
-
its("name") { should eq("John") }
|
42
|
-
its("name.size") { should eq(4) }
|
43
|
-
its("name.size.class") { should eq(Fixnum) }
|
44
24
|
|
45
|
-
context "
|
46
|
-
its(
|
25
|
+
context "with a call counter" do
|
26
|
+
its(:call_count) { should eq(1) }
|
47
27
|
end
|
48
28
|
|
49
|
-
context "
|
50
|
-
|
29
|
+
context "with nil value" do
|
30
|
+
subject do
|
31
|
+
Class.new do
|
32
|
+
def nil_value
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end.new
|
36
|
+
end
|
37
|
+
its(:nil_value) { should be_nil }
|
51
38
|
end
|
52
39
|
|
53
|
-
|
40
|
+
context "with nested attributes" do
|
41
|
+
subject do
|
42
|
+
Class.new do
|
43
|
+
def name
|
44
|
+
"John"
|
45
|
+
end
|
46
|
+
end.new
|
47
|
+
end
|
48
|
+
its("name") { should eq("John") }
|
49
|
+
its("name.size") { should eq(4) }
|
50
|
+
its("name.size.class") { should eq(Fixnum) }
|
54
51
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
52
|
+
context "using should_not" do
|
53
|
+
its("name") { should_not eq("Paul") }
|
54
|
+
end
|
55
|
+
|
56
|
+
context "using is_expected" do
|
57
|
+
its("name") { is_expected.to eq("John") }
|
58
|
+
end
|
63
59
|
|
64
|
-
def name
|
65
|
-
"George"
|
66
|
-
end
|
67
|
-
end.new
|
68
60
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
61
|
+
|
62
|
+
context "when it responds to #[]" do
|
63
|
+
subject do
|
64
|
+
Class.new do
|
65
|
+
def [](*objects)
|
66
|
+
objects.map do |object|
|
67
|
+
"#{object.class}: #{object.to_s}"
|
68
|
+
end.join("; ")
|
69
|
+
end
|
70
|
+
|
71
|
+
def name
|
72
|
+
"George"
|
73
|
+
end
|
74
|
+
end.new
|
75
|
+
end
|
76
|
+
its([:a]) { should eq("Symbol: a") }
|
77
|
+
its(['a']) { should eq("String: a") }
|
78
|
+
its([:b, 'c', 4]) { should eq("Symbol: b; String: c; Fixnum: 4") }
|
79
|
+
its(:name) { should eq("George") }
|
80
|
+
context "when referring to an attribute that doesn't exist" do
|
81
|
+
context "it raises an error" do
|
82
|
+
its(:age) do
|
83
|
+
expect do
|
84
|
+
should eq(64)
|
85
|
+
end.to raise_error(NoMethodError)
|
86
|
+
end
|
79
87
|
end
|
80
88
|
end
|
81
89
|
end
|
82
|
-
end
|
83
90
|
|
84
|
-
|
85
|
-
|
91
|
+
context "when it does not respond to #[]" do
|
92
|
+
subject { Object.new }
|
86
93
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
94
|
+
context "it raises an error" do
|
95
|
+
its([:a]) do
|
96
|
+
expect do
|
97
|
+
should eq("Symbol: a")
|
98
|
+
end.to raise_error(NoMethodError)
|
99
|
+
end
|
92
100
|
end
|
93
101
|
end
|
94
|
-
end
|
95
102
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
103
|
+
context "calling and overriding super" do
|
104
|
+
it "calls to the subject defined in the parent group" do
|
105
|
+
group = RSpec::Core::ExampleGroup.describe(Array) do
|
106
|
+
subject { [1, 'a'] }
|
100
107
|
|
101
|
-
|
108
|
+
its(:last) { should eq("a") }
|
102
109
|
|
103
|
-
|
104
|
-
|
110
|
+
describe '.first' do
|
111
|
+
def subject; super().first; end
|
105
112
|
|
106
|
-
|
113
|
+
its(:next) { should eq(2) }
|
114
|
+
end
|
107
115
|
end
|
116
|
+
|
117
|
+
expect(group.run(NullFormatter.new)).to be_truthy
|
108
118
|
end
|
119
|
+
end
|
109
120
|
|
110
|
-
|
121
|
+
context "with nil subject" do
|
122
|
+
subject do
|
123
|
+
Class.new do
|
124
|
+
def initialize
|
125
|
+
@counter = -1
|
126
|
+
end
|
127
|
+
def nil_if_first_time
|
128
|
+
@counter += 1
|
129
|
+
@counter == 0 ? nil : true
|
130
|
+
end
|
131
|
+
end.new
|
132
|
+
end
|
133
|
+
its(:nil_if_first_time) { should be(nil) }
|
111
134
|
end
|
112
|
-
end
|
113
135
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
136
|
+
context "with false subject" do
|
137
|
+
subject do
|
138
|
+
Class.new do
|
139
|
+
def initialize
|
140
|
+
@counter = -1
|
141
|
+
end
|
142
|
+
def false_if_first_time
|
143
|
+
@counter += 1
|
144
|
+
@counter > 0
|
145
|
+
end
|
146
|
+
end.new
|
147
|
+
end
|
148
|
+
its(:false_if_first_time) { should be(false) }
|
125
149
|
end
|
126
|
-
its(:nil_if_first_time) { should be(nil) }
|
127
|
-
end
|
128
150
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
151
|
+
describe 'accessing `subject` in `before` and `let`' do
|
152
|
+
subject { 'my subject' }
|
153
|
+
before { @subject_in_before = subject }
|
154
|
+
let(:subject_in_let) { subject }
|
155
|
+
let!(:eager_loaded_subject_in_let) { subject }
|
156
|
+
|
157
|
+
# These examples read weird, because we're actually
|
158
|
+
# specifying the behaviour of `its` itself
|
159
|
+
its(nil) { expect(subject).to eq('my subject') }
|
160
|
+
its(nil) { expect(@subject_in_before).to eq('my subject') }
|
161
|
+
its(nil) { expect(subject_in_let).to eq('my subject') }
|
162
|
+
its(nil) { expect(eager_loaded_subject_in_let).to eq('my subject') }
|
140
163
|
end
|
141
|
-
its(:false_if_first_time) { should be(false) }
|
142
|
-
end
|
143
164
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
# These examples read weird, because we're actually
|
151
|
-
# specifying the behaviour of `its` itself
|
152
|
-
its(nil) { expect(subject).to eq('my subject') }
|
153
|
-
its(nil) { expect(@subject_in_before).to eq('my subject') }
|
154
|
-
its(nil) { expect(subject_in_let).to eq('my subject') }
|
155
|
-
its(nil) { expect(eager_loaded_subject_in_let).to eq('my subject') }
|
156
|
-
end
|
165
|
+
describe "in shared_context" do
|
166
|
+
shared_context "shared stuff" do
|
167
|
+
subject {Array}
|
168
|
+
its(:name) {should eq "Array"}
|
169
|
+
end
|
157
170
|
|
158
|
-
|
159
|
-
shared_context "shared stuff" do
|
160
|
-
subject {Array}
|
161
|
-
its(:name) {should eq "Array"}
|
171
|
+
include_context "shared stuff"
|
162
172
|
end
|
163
173
|
|
164
|
-
|
165
|
-
|
174
|
+
describe "when extending SharedContext" do
|
175
|
+
it 'works with an implicit subject' do
|
176
|
+
shared = Module.new do
|
177
|
+
extend RSpec::SharedContext
|
178
|
+
its(:size) { should eq 0 }
|
179
|
+
end
|
180
|
+
group = RSpec::Core::ExampleGroup.describe(Array) do
|
181
|
+
include shared
|
182
|
+
end
|
166
183
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
extend RSpec::SharedContext
|
171
|
-
its(:size) { should eq 0 }
|
172
|
-
end
|
173
|
-
group = RSpec::Core::ExampleGroup.describe(Array) do
|
174
|
-
include shared
|
184
|
+
group.run(NullFormatter.new)
|
185
|
+
# Using to_h[:status].to_sym in following instead of .status due to need to run in RSpec 2.99
|
186
|
+
expect(group.children.first.examples.first.execution_result.to_h[:status].to_sym).to eq(:passed)
|
175
187
|
end
|
176
|
-
|
177
|
-
group.run(NullFormatter.new)
|
178
|
-
expect(group.children.first.examples.first.execution_result).to include(:status => "passed")
|
179
188
|
end
|
180
189
|
end
|
181
190
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-its
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Alfvin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|