rspec-its 1.0.1 → 1.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 +7 -4
- data/Changelog.md +13 -0
- data/Gemfile +2 -3
- data/README.md +20 -2
- data/features/its.feature +24 -0
- data/features/step_definitions/additional_cli_steps.rb +8 -0
- data/lib/rspec/its.rb +35 -9
- data/lib/rspec/its/version.rb +1 -1
- data/rspec-its.gemspec +3 -3
- data/spec/rspec/its_spec.rb +27 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab33dd1641758cc1d81b57418e598d6d41fc739a
|
4
|
+
data.tar.gz: 9235487eef7281417d50bc7342e71baa66779914
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6ed4e65790cb3c9a2a21bc7a9493dba9e41c890f19ebea44489de827da75ec5a22a0626bffcbcba8f4929d33879892cb5f05faab4a0dd60f5fe3c57dc9c5c76
|
7
|
+
data.tar.gz: bcf65bcdad2fb1b8398817728e20f88b0494906e8f0a9b374042092caccf7a3e7314ef9f1238a24cf5c9bf212c707d99c6bebb29b222e36729e77f3850329b59
|
data/.travis.yml
CHANGED
@@ -7,14 +7,17 @@ rvm:
|
|
7
7
|
- 1.9.3
|
8
8
|
- 2.0.0
|
9
9
|
- 2.1.0
|
10
|
+
- 2.1.1
|
11
|
+
- 2.1.2
|
12
|
+
- ruby-head
|
10
13
|
- ree
|
11
14
|
- jruby-18mode
|
12
15
|
- jruby
|
16
|
+
- jruby-head
|
13
17
|
- rbx
|
14
|
-
env:
|
15
|
-
- BRANCH=master
|
16
|
-
- BRANCH=2-99-maintenance
|
17
18
|
matrix:
|
18
19
|
allow_failures:
|
19
|
-
- rvm: jruby-
|
20
|
+
- rvm: jruby-head
|
21
|
+
- rvm: ruby-head
|
22
|
+
- rvm: rbx
|
20
23
|
|
data/Changelog.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
### 1.1.0 / 2014-04-13
|
2
|
+
[full changelog](http://github.com/rspec/rspec-its/compare/v1.0.1...v1.1.0)
|
3
|
+
|
4
|
+
Breaking Changes:
|
5
|
+
|
6
|
+
Enhancements:
|
7
|
+
* For hashes, multiple array elements are treated as successive access keys
|
8
|
+
* Metadata arguments are now supported
|
9
|
+
|
10
|
+
Bug fixes:
|
11
|
+
* Enable `its` example selection by line number in command line
|
12
|
+
|
13
|
+
|
1
14
|
### 1.0.1 / 2014-04-13
|
2
15
|
[full changelog](http://github.com/rspec/rspec-its/compare/v1.0.0...v1.0.1)
|
3
16
|
|
data/Gemfile
CHANGED
@@ -4,8 +4,7 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
|
7
|
-
branch = ENV.fetch('BRANCH','
|
8
|
-
next if branch == '2-99-maintenance' && lib == 'rspec-support'
|
7
|
+
branch = ENV.fetch('BRANCH','3-1-maintenance')
|
9
8
|
library_path = File.expand_path("../../#{lib}", __FILE__)
|
10
9
|
if File.exist?(library_path)
|
11
10
|
gem lib, :path => library_path
|
@@ -24,4 +23,4 @@ eval File.read('Gemfile-custom') if File.exist?('Gemfile-custom')
|
|
24
23
|
|
25
24
|
platform :rbx do
|
26
25
|
gem 'rubysl'
|
27
|
-
end
|
26
|
+
end
|
data/README.md
CHANGED
@@ -16,6 +16,10 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install rspec-its
|
18
18
|
|
19
|
+
And require it as:
|
20
|
+
|
21
|
+
require 'rspec/its'
|
22
|
+
|
19
23
|
## Usage
|
20
24
|
|
21
25
|
Use the `its` method to generate a nested example group with
|
@@ -32,11 +36,25 @@ attribute of the attribute of the subject).
|
|
32
36
|
|
33
37
|
its("phone_numbers.size") { should_not eq(0) }
|
34
38
|
|
35
|
-
When the subject
|
36
|
-
|
39
|
+
When the subject implements the `[]` operator, you can pass in an array with a single key to
|
40
|
+
refer to the value returned by that operator when passed that key as an argument.
|
37
41
|
|
38
42
|
its([:key]) { is_expected.to eq(value) }
|
39
43
|
|
44
|
+
For hashes, multiple keys within the array will result in successive accesses into the hash. For example:
|
45
|
+
|
46
|
+
subject { {key1: {key2: 3} } }
|
47
|
+
its([:key1, :key2]) { is_expected.to eq(3)
|
48
|
+
|
49
|
+
For other objects, multiple keys within the array will be passed as separate arguments in a single method call to [], as in:
|
50
|
+
|
51
|
+
subject { Matrix[ [:a, :b], [:c, :d] ] }
|
52
|
+
its([1,1]) { should eq(:d) }
|
53
|
+
|
54
|
+
Metadata arguments are supported.
|
55
|
+
|
56
|
+
its(:size, focus: true) { should eq(1) }
|
57
|
+
|
40
58
|
## Contributing
|
41
59
|
|
42
60
|
1. Fork it
|
data/features/its.feature
CHANGED
@@ -96,3 +96,27 @@ Feature: attribute of subject
|
|
96
96
|
When I run rspec
|
97
97
|
Then the output should contain "Failure/Error: its(:size) { should_not eq(0) }"
|
98
98
|
And the output should not match /#[^\n]*rspec[\x2f]its/
|
99
|
+
|
100
|
+
Scenario: examples can be specified by exact line number
|
101
|
+
Given a file named "example_spec.rb" with:
|
102
|
+
"""ruby
|
103
|
+
describe Array do
|
104
|
+
context "when first created" do
|
105
|
+
its(:size) { should eq(0) }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
"""
|
109
|
+
When I run rspec specifying line number 3
|
110
|
+
Then the examples should all pass
|
111
|
+
|
112
|
+
Scenario: examples can be specified by line number within containing block
|
113
|
+
Given a file named "example_spec.rb" with:
|
114
|
+
"""ruby
|
115
|
+
describe Array do
|
116
|
+
context "when first created" do
|
117
|
+
its(:size) { should eq(0) }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
"""
|
121
|
+
When I run rspec specifying line number 2
|
122
|
+
Then the examples should all pass
|
@@ -6,6 +6,14 @@ When /^I run rspec( with the documentation option)?$/ do |documentation|
|
|
6
6
|
step "I run `#{rspec_command}`"
|
7
7
|
end
|
8
8
|
|
9
|
+
When /^I run rspec specifying line number (\d+)$/ do |line_number|
|
10
|
+
rspec_its_gem_location = File.expand_path('../../../lib/rspec/its', __FILE__)
|
11
|
+
require_option = "--require #{rspec_its_gem_location}"
|
12
|
+
file_specification = "example_spec.rb:#{line_number}"
|
13
|
+
rspec_command = ['rspec', require_option, file_specification].join(' ')
|
14
|
+
step "I run `#{rspec_command}`"
|
15
|
+
end
|
16
|
+
|
9
17
|
Then /^the example(?:s)? should(?: all)? pass$/ do
|
10
18
|
step %q{the output should contain "0 failures"}
|
11
19
|
step %q{the output should not contain "0 examples"}
|
data/lib/rspec/its.rb
CHANGED
@@ -47,11 +47,13 @@ module RSpec
|
|
47
47
|
# describe "a configuration Hash" do
|
48
48
|
# subject do
|
49
49
|
# { :max_users => 3,
|
50
|
-
# 'admin' => :all_permissions
|
50
|
+
# 'admin' => :all_permissions.
|
51
|
+
# 'john_doe' => {:permissions => [:read, :write]}}
|
51
52
|
# end
|
52
53
|
#
|
53
54
|
# its([:max_users]) { should eq(3) }
|
54
55
|
# its(['admin']) { should eq(:all_permissions) }
|
56
|
+
# its(['john_doe', :permissions]) { should eq([:read, :write]) }
|
55
57
|
#
|
56
58
|
# # You can still access to its regular methods this way:
|
57
59
|
# its(:keys) { should include(:max_users) }
|
@@ -67,6 +69,25 @@ module RSpec
|
|
67
69
|
# its(:size) { is_expected.to eq(0) }
|
68
70
|
# end
|
69
71
|
#
|
72
|
+
# You can pass more than one arguments on the `its` block to add
|
73
|
+
# some options to the generated example
|
74
|
+
#
|
75
|
+
# @example
|
76
|
+
#
|
77
|
+
# # This ...
|
78
|
+
# describe Array do
|
79
|
+
# its(:size, :focus) { should eq(0) }
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# # ... generates the same runtime structure as this:
|
83
|
+
# describe Array do
|
84
|
+
# describe "size" do
|
85
|
+
# it "should eq(0)", :focus do
|
86
|
+
# subject.size.should eq(0)
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
#
|
70
91
|
# Note that this method does not modify `subject` in any way, so if you
|
71
92
|
# refer to `subject` in `let` or `before` blocks, you're still
|
72
93
|
# referring to the outer subject.
|
@@ -78,12 +99,17 @@ module RSpec
|
|
78
99
|
# before { subject.age = 25 }
|
79
100
|
# its(:age) { should eq(25) }
|
80
101
|
# end
|
81
|
-
def its(attribute, &block)
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
102
|
+
def its(attribute, *options, &block)
|
103
|
+
its_caller = caller.select {|file_line| file_line !~ %r(/lib/rspec/its) }
|
104
|
+
describe(attribute.to_s, :caller => its_caller) do
|
105
|
+
let(:__its_subject) do
|
106
|
+
if Array === attribute
|
107
|
+
if Hash === subject
|
108
|
+
attribute.inject(subject) {|inner, attr| inner[attr] }
|
109
|
+
else
|
110
|
+
subject[*attribute]
|
111
|
+
end
|
112
|
+
else
|
87
113
|
attribute_chain = attribute.to_s.split('.')
|
88
114
|
attribute_chain.inject(subject) do |inner_subject, attr|
|
89
115
|
inner_subject.send(attr)
|
@@ -103,8 +129,8 @@ module RSpec
|
|
103
129
|
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(__its_subject, matcher, message)
|
104
130
|
end
|
105
131
|
|
106
|
-
|
107
|
-
example(nil,
|
132
|
+
options << { :caller => its_caller }
|
133
|
+
example(nil, *options, &block)
|
108
134
|
|
109
135
|
end
|
110
136
|
end
|
data/lib/rspec/its/version.rb
CHANGED
data/rspec-its.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["palfvin@gmail.com"]
|
11
11
|
spec.description = %q{RSpec extension gem for attribute matching}
|
12
12
|
spec.summary = %q{Provides "its" method formally part of rspec-core}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/rspec/rspec-its"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency 'rspec-core', '>=
|
22
|
-
spec.add_runtime_dependency 'rspec-expectations', '>=
|
21
|
+
spec.add_runtime_dependency 'rspec-core', '>= 3.0.0'
|
22
|
+
spec.add_runtime_dependency 'rspec-expectations', '>= 3.0.0'
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
24
|
spec.add_development_dependency 'rake', '~> 10.1.0'
|
25
25
|
spec.add_development_dependency 'cucumber', '~> 1.3.8'
|
data/spec/rspec/its_spec.rb
CHANGED
@@ -22,6 +22,14 @@ module RSpec
|
|
22
22
|
end.new
|
23
23
|
end
|
24
24
|
|
25
|
+
before(:each, :meta) do
|
26
|
+
subject.call_count
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with some metadata" do
|
30
|
+
its(:call_count, :meta) { should eq(2) }
|
31
|
+
end
|
32
|
+
|
25
33
|
context "with a call counter" do
|
26
34
|
its(:call_count) { should eq(1) }
|
27
35
|
end
|
@@ -86,6 +94,20 @@ module RSpec
|
|
86
94
|
end
|
87
95
|
end
|
88
96
|
end
|
97
|
+
|
98
|
+
context "when it's a hash" do
|
99
|
+
subject { {:a => {:deep => {:key => "value"}}} }
|
100
|
+
|
101
|
+
its([:a]) { should eq({:deep => {:key => "value"}}) }
|
102
|
+
its([:a, :deep]) { should eq({:key => "value"}) }
|
103
|
+
its([:a, :deep, :key]) { should eq("value") }
|
104
|
+
|
105
|
+
context "when referring to a key that doesn't exist" do
|
106
|
+
its([:not_here]) { should be_nil }
|
107
|
+
its([:a, :ghost]) { should be_nil }
|
108
|
+
its([:deep, :ghost]) { expect { should eq("missing") }.to raise_error(NoMethodError) }
|
109
|
+
end
|
110
|
+
end
|
89
111
|
end
|
90
112
|
|
91
113
|
context "when it does not respond to #[]" do
|
@@ -182,8 +204,11 @@ module RSpec
|
|
182
204
|
end
|
183
205
|
|
184
206
|
group.run(NullFormatter.new)
|
185
|
-
|
186
|
-
|
207
|
+
|
208
|
+
result = group.children.first.examples.first.execution_result
|
209
|
+
# Following conditional needed to work across mix of RSpec and ruby versions without warning
|
210
|
+
status = result.respond_to?(:status) ? result.status : result[:status].to_sym
|
211
|
+
expect(status).to eq(:passed)
|
187
212
|
end
|
188
213
|
end
|
189
214
|
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.1.0
|
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-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec-expectations
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,7 +119,7 @@ files:
|
|
119
119
|
- script/test_all
|
120
120
|
- spec/rspec/its_spec.rb
|
121
121
|
- spec/spec_helper.rb
|
122
|
-
homepage:
|
122
|
+
homepage: https://github.com/rspec/rspec-its
|
123
123
|
licenses:
|
124
124
|
- MIT
|
125
125
|
metadata: {}
|