rspec-its 0.0.1.pre → 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rspec +3 -0
- data/.travis.yml +17 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +7 -2
- data/README.md +20 -3
- data/Rakefile +16 -1
- data/cucumber.yml +2 -0
- data/features/its.feature +122 -0
- data/features/step_definitions/additional_cli_steps.rb +13 -0
- data/features/support/env.rb +23 -0
- data/lib/rspec/its.rb +104 -0
- data/lib/rspec/its/version.rb +5 -0
- data/rspec-its.gemspec +21 -14
- data/script/test_all +20 -0
- data/spec/rspec/its_spec.rb +176 -0
- data/spec/spec_helper.rb +15 -0
- metadata +87 -20
- data/lib/rspec-its.rb +0 -7
- data/lib/rspec-its/version.rb +0 -6
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 74d74f8141ca983bbc9d83d3d182a0190f46509e
|
4
|
+
data.tar.gz: 07155718c11bb44984f207e4df93a852bfab5917
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9bf5f5c666977b852792854fe7558829c64bb5e4a46418dd4c82c04dec1329c6eee1b0e11826bbf879afcb3fbb3e8158d2853ed74ff405ce6bca1e57dd542002
|
7
|
+
data.tar.gz: 7562f702a727bc65ad81a8de119eb03356a120127e32331b0eedfca5ebcf5ea29fb3029c25ea783742f33ff312263629664c4182bb45a7efcba9b27f7762ecbe
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
script: "script/test_all"
|
3
|
+
bundler_args: "--standalone --binstubs --without documentation"
|
4
|
+
rvm:
|
5
|
+
- 1.8.7
|
6
|
+
- 1.9.2
|
7
|
+
- 1.9.3
|
8
|
+
- ree
|
9
|
+
- jruby-18mode
|
10
|
+
- jruby-19mode
|
11
|
+
- rbx-18mode
|
12
|
+
- rbx-19mode
|
13
|
+
- 2.0.0
|
14
|
+
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: rbx-19mode
|
17
|
+
- rvm: rbx-18mode
|
data/Gemfile
CHANGED
@@ -2,3 +2,18 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in rspec-its.gemspec
|
4
4
|
gemspec
|
5
|
+
|
6
|
+
%w[rspec rspec-core rspec-expectations rspec-mocks].each do |lib|
|
7
|
+
library_path = File.expand_path("../../#{lib}", __FILE__)
|
8
|
+
if File.exist?(library_path)
|
9
|
+
gem lib, :path => library_path
|
10
|
+
else
|
11
|
+
gem lib, :git => "git://github.com/rspec/#{lib}.git"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# test coverage
|
16
|
+
gem 'simplecov', :require => false
|
17
|
+
gem 'coveralls', :require => false
|
18
|
+
|
19
|
+
eval File.read('Gemfile-custom') if File.exist?('Gemfile-custom')
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Peter Alfvin
|
4
|
+
Copyright (c) 2012 David Chelimsky, Myron Marston
|
5
|
+
Copyright (c) 2006 David Chelimsky, The RSpec Development Team
|
6
|
+
Copyright (c) 2005 Steven Baker
|
2
7
|
|
3
8
|
MIT License
|
4
9
|
|
@@ -19,4 +24,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
24
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
25
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
26
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# RSpec::Its [![Build Status](https://travis-ci.org/palfvin/rspec-its.png)](https://travis-ci.org/palfvin/rspec-its)
|
2
2
|
|
3
|
-
|
3
|
+
RSpec::Its provides the `its` method as a short-hand to specify the expected value of an attribute.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,24 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Use the `its` method to generate a nested example group with
|
22
|
+
a single example that specifies the expected value of an attribute of the
|
23
|
+
subject. This can be used with an implicit or explicit subject.
|
24
|
+
|
25
|
+
`its` accepts a symbol or a string, and a block representing the example.
|
26
|
+
|
27
|
+
its(:size) { should eq(1) }
|
28
|
+
its("length") { should eq(1) }
|
29
|
+
|
30
|
+
You can use a string with dots to specify a nested attribute (i.e. an
|
31
|
+
attribute of the attribute of the subject).
|
32
|
+
|
33
|
+
its("phone_numbers.size") { should eq(2) }
|
34
|
+
|
35
|
+
When the subject is a hash, you can pass in an array with a single key to
|
36
|
+
access the value at that key in the hash.
|
37
|
+
|
38
|
+
its([:key]) { should eq(value) }
|
22
39
|
|
23
40
|
## Contributing
|
24
41
|
|
data/Rakefile
CHANGED
@@ -1 +1,16 @@
|
|
1
|
-
require "bundler
|
1
|
+
require "bundler"
|
2
|
+
Bundler.setup
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
require "rake"
|
6
|
+
require "rspec/core/rake_task"
|
7
|
+
|
8
|
+
require "cucumber/rake/task"
|
9
|
+
Cucumber::Rake::Task.new(:cucumber)
|
10
|
+
|
11
|
+
desc "Run all examples"
|
12
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
13
|
+
t.ruby_opts = %w[-w]
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => [:spec, :cucumber]
|
data/cucumber.yml
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
Feature: attribute of subject
|
2
|
+
|
3
|
+
Use the `its` method as a short-hand to generate a nested example group with
|
4
|
+
a single example that specifies the expected value of an attribute of the
|
5
|
+
subject. This can be used with an implicit or explicit subject.
|
6
|
+
|
7
|
+
`its` accepts a symbol or a string, and a block representing the example.
|
8
|
+
|
9
|
+
its(:size) { should eq(1) }
|
10
|
+
its("length") { should eq(1) }
|
11
|
+
|
12
|
+
You can use a string with dots to specify a nested attribute (i.e. an
|
13
|
+
attribute of the attribute of the subject).
|
14
|
+
|
15
|
+
its("phone_numbers.size") { should eq(2) }
|
16
|
+
|
17
|
+
When the subject is a hash, you can pass in an array with a single key to
|
18
|
+
access the value at that key in the hash.
|
19
|
+
|
20
|
+
its([:key]) { should eq(value) }
|
21
|
+
|
22
|
+
Scenario: specify value of an attribute
|
23
|
+
Given a file named "example_spec.rb" with:
|
24
|
+
"""ruby
|
25
|
+
describe Array do
|
26
|
+
context "when first created" do
|
27
|
+
its(:size) { should eq(0) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
"""
|
31
|
+
When I run rspec with the documentation option
|
32
|
+
Then the output should contain:
|
33
|
+
"""
|
34
|
+
Array
|
35
|
+
when first created
|
36
|
+
size
|
37
|
+
should eq 0
|
38
|
+
"""
|
39
|
+
|
40
|
+
Scenario: specify value of a nested attribute
|
41
|
+
Given a file named "example_spec.rb" with:
|
42
|
+
"""ruby
|
43
|
+
class Person
|
44
|
+
attr_reader :phone_numbers
|
45
|
+
def initialize
|
46
|
+
@phone_numbers = []
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe Person do
|
51
|
+
context "with one phone number (555-1212)"do
|
52
|
+
subject do
|
53
|
+
person = Person.new
|
54
|
+
person.phone_numbers << "555-1212"
|
55
|
+
person
|
56
|
+
end
|
57
|
+
|
58
|
+
its("phone_numbers.first") { should eq("555-1212") }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
"""
|
62
|
+
When I run rspec with the documentation option
|
63
|
+
Then the output should contain:
|
64
|
+
"""
|
65
|
+
Person
|
66
|
+
with one phone number (555-1212)
|
67
|
+
phone_numbers.first
|
68
|
+
should eq "555-1212"
|
69
|
+
"""
|
70
|
+
|
71
|
+
Scenario: specify value of an attribute of a hash
|
72
|
+
Given a file named "example_spec.rb" with:
|
73
|
+
"""ruby
|
74
|
+
describe Hash do
|
75
|
+
context "with two items" do
|
76
|
+
subject do
|
77
|
+
{:one => 'one', :two => 'two'}
|
78
|
+
end
|
79
|
+
|
80
|
+
its(:size) { should eq(2) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
"""
|
84
|
+
When I run rspec
|
85
|
+
Then the examples should all pass
|
86
|
+
|
87
|
+
Scenario: specify value for key in a hash
|
88
|
+
Given a file named "example_spec.rb" with:
|
89
|
+
"""ruby
|
90
|
+
describe Hash do
|
91
|
+
context "with keys :one and 'two'" do
|
92
|
+
subject do
|
93
|
+
{:one => 1, "two" => 2}
|
94
|
+
end
|
95
|
+
|
96
|
+
its([:one]) { should eq(1) }
|
97
|
+
its(["two"]) { should eq(2) }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
"""
|
101
|
+
When I run rspec
|
102
|
+
Then the examples should all pass
|
103
|
+
|
104
|
+
Scenario: specify value for key in a hash-like object
|
105
|
+
Given a file named "example_spec.rb" with:
|
106
|
+
"""ruby
|
107
|
+
require 'matrix'
|
108
|
+
|
109
|
+
describe Matrix do
|
110
|
+
context "with values [[1, 2], [3, 4]]" do
|
111
|
+
subject do
|
112
|
+
Matrix[[1, 2], [3, 4]]
|
113
|
+
end
|
114
|
+
|
115
|
+
its([0, 1]) { should eq(2) }
|
116
|
+
its([1, 0]) { should eq(3) }
|
117
|
+
its([1, 2]) { should be_nil }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
"""
|
121
|
+
When I run rspec
|
122
|
+
Then the examples should all pass
|
@@ -0,0 +1,13 @@
|
|
1
|
+
When /^I run rspec( with the documentation option)?$/ do |documentation|
|
2
|
+
rspec_its_gem_location = File.expand_path('../../../lib/rspec/its', __FILE__)
|
3
|
+
require_option = "--require #{rspec_its_gem_location}"
|
4
|
+
format_option = documentation ? "--format documentation" : ""
|
5
|
+
rspec_command = ['rspec', require_option, format_option, 'example_spec.rb'].join(' ')
|
6
|
+
step "I run `#{rspec_command}`"
|
7
|
+
end
|
8
|
+
|
9
|
+
Then /^the example(?:s)? should(?: all)? pass$/ do
|
10
|
+
step %q{the output should contain "0 failures"}
|
11
|
+
step %q{the output should not contain "0 examples"}
|
12
|
+
step %q{the exit status should be 0}
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'aruba/cucumber'
|
2
|
+
require 'rspec/core'
|
3
|
+
require 'rspec/its'
|
4
|
+
|
5
|
+
Before do
|
6
|
+
if RUBY_PLATFORM =~ /java/ || defined?(Rubinius)
|
7
|
+
@aruba_timeout_seconds = 60
|
8
|
+
else
|
9
|
+
@aruba_timeout_seconds = 10
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Aruba.configure do |config|
|
14
|
+
config.before_cmd do |cmd|
|
15
|
+
set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived
|
16
|
+
end
|
17
|
+
end if RUBY_PLATFORM == 'java'
|
18
|
+
|
19
|
+
Aruba.configure do |config|
|
20
|
+
config.before_cmd do |cmd|
|
21
|
+
set_env('RBXOPT', "-Xint=true #{ENV['RBXOPT']}") # disable JIT since these processes are so short lived
|
22
|
+
end
|
23
|
+
end if defined?(Rubinius)
|
data/lib/rspec/its.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'rspec/its/version'
|
2
|
+
require 'rspec/core'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module Its
|
6
|
+
|
7
|
+
# Creates a nested example group named by the submitted `attribute`,
|
8
|
+
# and then generates an example using the submitted block.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
#
|
12
|
+
# # This ...
|
13
|
+
# describe Array do
|
14
|
+
# its(:size) { should eq(0) }
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # ... generates the same runtime structure as this:
|
18
|
+
# describe Array do
|
19
|
+
# describe "size" do
|
20
|
+
# it "should eq(0)" do
|
21
|
+
# subject.size.should eq(0)
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# The attribute can be a `Symbol` or a `String`. Given a `String`
|
27
|
+
# with dots, the result is as though you concatenated that `String`
|
28
|
+
# onto the subject in an expression.
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
#
|
32
|
+
# describe Person do
|
33
|
+
# subject do
|
34
|
+
# Person.new.tap do |person|
|
35
|
+
# person.phone_numbers << "555-1212"
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# its("phone_numbers.first") { should eq("555-1212") }
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# When the subject is a `Hash`, you can refer to the Hash keys by
|
43
|
+
# specifying a `Symbol` or `String` in an array.
|
44
|
+
#
|
45
|
+
# @example
|
46
|
+
#
|
47
|
+
# describe "a configuration Hash" do
|
48
|
+
# subject do
|
49
|
+
# { :max_users => 3,
|
50
|
+
# 'admin' => :all_permissions }
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# its([:max_users]) { should eq(3) }
|
54
|
+
# its(['admin']) { should eq(:all_permissions) }
|
55
|
+
#
|
56
|
+
# # You can still access to its regular methods this way:
|
57
|
+
# its(:keys) { should include(:max_users) }
|
58
|
+
# its(:count) { should eq(2) }
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# Note that this method does not modify `subject` in any way, so if you
|
62
|
+
# refer to `subject` in `let` or `before` blocks, you're still
|
63
|
+
# referring to the outer subject.
|
64
|
+
#
|
65
|
+
# @example
|
66
|
+
#
|
67
|
+
# describe Person do
|
68
|
+
# subject { Person.new }
|
69
|
+
# before { subject.age = 25 }
|
70
|
+
# its(:age) { should eq(25) }
|
71
|
+
# end
|
72
|
+
def its(attribute, &block)
|
73
|
+
describe(attribute) do
|
74
|
+
if Array === attribute
|
75
|
+
let(:__its_subject) { subject[*attribute] }
|
76
|
+
else
|
77
|
+
let(:__its_subject) do
|
78
|
+
attribute_chain = attribute.to_s.split('.')
|
79
|
+
attribute_chain.inject(subject) do |inner_subject, attr|
|
80
|
+
inner_subject.send(attr)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def should(matcher=nil, message=nil)
|
86
|
+
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(__its_subject, matcher, message)
|
87
|
+
end
|
88
|
+
|
89
|
+
def should_not(matcher=nil, message=nil)
|
90
|
+
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(__its_subject, matcher, message)
|
91
|
+
end
|
92
|
+
|
93
|
+
example(&block)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
RSpec.configure do |rspec|
|
101
|
+
rspec.extend RSpec::Its
|
102
|
+
end
|
103
|
+
|
104
|
+
RSpec::SharedContext.send(:include, RSpec::Its)
|
data/rspec-its.gemspec
CHANGED
@@ -1,19 +1,26 @@
|
|
1
|
-
#
|
1
|
+
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'rspec
|
4
|
+
require 'rspec/its/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-its"
|
8
|
+
spec.version = RSpec::Its::VERSION
|
9
|
+
spec.authors = ["Peter Alfvin"]
|
10
|
+
spec.email = ["palfvin@gmail.com"]
|
11
|
+
spec.description = %q{RSpec extension gem for attribute matching}
|
12
|
+
spec.summary = %q{Provides "its" method formally part of rspec-core}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.1.0'
|
23
|
+
spec.add_development_dependency 'cucumber', '~> 1.3.8'
|
24
|
+
spec.add_development_dependency 'aruba', '~> 0.5'
|
14
25
|
|
15
|
-
gem.files = `git ls-files`.split($/)
|
16
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = ["lib"]
|
19
26
|
end
|
data/script/test_all
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e -x
|
4
|
+
|
5
|
+
# idea taken from: http://blog.headius.com/2010/03/jruby-startup-time-tips.html
|
6
|
+
export JRUBY_OPTS='-X-C' # disable JIT since these processes are so short lived
|
7
|
+
|
8
|
+
# force jRuby to use client mode JVM or a compilation mode thats as close as possible,
|
9
|
+
# idea taken from https://github.com/jruby/jruby/wiki/Improving-startup-time
|
10
|
+
export JAVA_OPTS='-client -XX:+TieredCompilation -XX:TieredStopAtLevel=1'
|
11
|
+
|
12
|
+
echo "Running rspec specs"
|
13
|
+
bin/rspec spec --format progress --profile
|
14
|
+
|
15
|
+
echo "Running cucumber specs"
|
16
|
+
# TODO: it would be nice to figure out how to run the cukes w/o the overhead of
|
17
|
+
# bundler, but just running `bin/cucumber` can fail due to the fact that it
|
18
|
+
# shells out (via aruba) and executes `rspec`--which can pick up the wrong
|
19
|
+
# rspec version if we're not running with bundler.
|
20
|
+
bundle exec cucumber
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
describe Its do
|
5
|
+
describe "#its" do
|
6
|
+
subject do
|
7
|
+
Class.new do
|
8
|
+
def initialize
|
9
|
+
@call_count = 0
|
10
|
+
end
|
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) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with nil value" do
|
23
|
+
subject do
|
24
|
+
Class.new do
|
25
|
+
def nil_value
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
end.new
|
29
|
+
end
|
30
|
+
its(:nil_value) { should be_nil }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with nested attributes" do
|
34
|
+
subject do
|
35
|
+
Class.new do
|
36
|
+
def name
|
37
|
+
"John"
|
38
|
+
end
|
39
|
+
end.new
|
40
|
+
end
|
41
|
+
its("name") { should eq("John") }
|
42
|
+
its("name.size") { should eq(4) }
|
43
|
+
its("name.size.class") { should eq(Fixnum) }
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when it responds to #[]" do
|
47
|
+
subject do
|
48
|
+
Class.new do
|
49
|
+
def [](*objects)
|
50
|
+
objects.map do |object|
|
51
|
+
"#{object.class}: #{object.to_s}"
|
52
|
+
end.join("; ")
|
53
|
+
end
|
54
|
+
|
55
|
+
def name
|
56
|
+
"George"
|
57
|
+
end
|
58
|
+
end.new
|
59
|
+
end
|
60
|
+
its([:a]) { should eq("Symbol: a") }
|
61
|
+
its(['a']) { should eq("String: a") }
|
62
|
+
its([:b, 'c', 4]) { should eq("Symbol: b; String: c; Fixnum: 4") }
|
63
|
+
its(:name) { should eq("George") }
|
64
|
+
context "when referring to an attribute without the proper array syntax" do
|
65
|
+
context "it raises an error" do
|
66
|
+
its(:age) do
|
67
|
+
expect do
|
68
|
+
should eq(64)
|
69
|
+
end.to raise_error(NoMethodError)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when it does not respond to #[]" do
|
76
|
+
subject { Object.new }
|
77
|
+
|
78
|
+
context "it raises an error" do
|
79
|
+
its([:a]) do
|
80
|
+
expect do
|
81
|
+
should eq("Symbol: a")
|
82
|
+
end.to raise_error(NoMethodError)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "calling and overriding super" do
|
88
|
+
it "calls to the subject defined in the parent group" do
|
89
|
+
group = RSpec::Core::ExampleGroup.describe(Array) do
|
90
|
+
subject { [1, 'a'] }
|
91
|
+
|
92
|
+
its(:last) { should eq("a") }
|
93
|
+
|
94
|
+
describe '.first' do
|
95
|
+
def subject; super().first; end
|
96
|
+
|
97
|
+
its(:next) { should eq(2) }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
expect(group.run(NullFormatter.new)).to be_truthy
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "with nil subject" do
|
106
|
+
subject do
|
107
|
+
Class.new do
|
108
|
+
def initialize
|
109
|
+
@counter = -1
|
110
|
+
end
|
111
|
+
def nil_if_first_time
|
112
|
+
@counter += 1
|
113
|
+
@counter == 0 ? nil : true
|
114
|
+
end
|
115
|
+
end.new
|
116
|
+
end
|
117
|
+
its(:nil_if_first_time) { should be(nil) }
|
118
|
+
end
|
119
|
+
|
120
|
+
context "with false subject" do
|
121
|
+
subject do
|
122
|
+
Class.new do
|
123
|
+
def initialize
|
124
|
+
@counter = -1
|
125
|
+
end
|
126
|
+
def false_if_first_time
|
127
|
+
@counter += 1
|
128
|
+
@counter > 0
|
129
|
+
end
|
130
|
+
end.new
|
131
|
+
end
|
132
|
+
its(:false_if_first_time) { should be(false) }
|
133
|
+
end
|
134
|
+
|
135
|
+
describe 'accessing `subject` in `before` and `let`' do
|
136
|
+
subject { 'my subject' }
|
137
|
+
before { @subject_in_before = subject }
|
138
|
+
let(:subject_in_let) { subject }
|
139
|
+
let!(:eager_loaded_subject_in_let) { subject }
|
140
|
+
|
141
|
+
# These examples read weird, because we're actually
|
142
|
+
# specifying the behaviour of `its` itself
|
143
|
+
its(nil) { expect(subject).to eq('my subject') }
|
144
|
+
its(nil) { expect(@subject_in_before).to eq('my subject') }
|
145
|
+
its(nil) { expect(subject_in_let).to eq('my subject') }
|
146
|
+
its(nil) { expect(eager_loaded_subject_in_let).to eq('my subject') }
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "in shared_context" do
|
150
|
+
shared_context "shared stuff" do
|
151
|
+
subject {Array}
|
152
|
+
its(:name) {should eq "Array"}
|
153
|
+
end
|
154
|
+
|
155
|
+
include_context "shared stuff"
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "when extending SharedContext" do
|
159
|
+
it 'works with an implicit subject' do
|
160
|
+
shared = Module.new do
|
161
|
+
extend RSpec::SharedContext
|
162
|
+
its(:size) { should eq 0 }
|
163
|
+
end
|
164
|
+
group = RSpec::Core::ExampleGroup.describe(Array) do
|
165
|
+
include shared
|
166
|
+
end
|
167
|
+
|
168
|
+
group.run(NullFormatter.new)
|
169
|
+
expect(group.children.first.examples.first.execution_result).to include(:status => "passed")
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rspec/its'
|
2
|
+
|
3
|
+
Dir['./spec/support/**/*'].each {|f| require f}
|
4
|
+
|
5
|
+
class NullFormatter
|
6
|
+
private
|
7
|
+
def method_missing(method, *args, &block)
|
8
|
+
# ignore
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.order = 'random'
|
15
|
+
end
|
metadata
CHANGED
@@ -1,55 +1,122 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-its
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease: 6
|
4
|
+
version: 1.0.0.pre
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
|
-
-
|
7
|
+
- Peter Alfvin
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
14
|
-
|
15
|
-
|
11
|
+
date: 2013-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 10.1.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 10.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cucumber
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.3.8
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.3.8
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aruba
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.5'
|
69
|
+
description: RSpec extension gem for attribute matching
|
16
70
|
email:
|
17
|
-
-
|
71
|
+
- palfvin@gmail.com
|
18
72
|
executables: []
|
19
73
|
extensions: []
|
20
74
|
extra_rdoc_files: []
|
21
75
|
files:
|
22
76
|
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- .travis.yml
|
23
79
|
- Gemfile
|
24
80
|
- LICENSE.txt
|
25
81
|
- README.md
|
26
82
|
- Rakefile
|
27
|
-
-
|
28
|
-
-
|
83
|
+
- cucumber.yml
|
84
|
+
- features/its.feature
|
85
|
+
- features/step_definitions/additional_cli_steps.rb
|
86
|
+
- features/support/env.rb
|
87
|
+
- lib/rspec/its.rb
|
88
|
+
- lib/rspec/its/version.rb
|
29
89
|
- rspec-its.gemspec
|
90
|
+
- script/test_all
|
91
|
+
- spec/rspec/its_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
30
93
|
homepage: ''
|
31
|
-
licenses:
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
32
97
|
post_install_message:
|
33
98
|
rdoc_options: []
|
34
99
|
require_paths:
|
35
100
|
- lib
|
36
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
37
102
|
requirements:
|
38
|
-
- -
|
103
|
+
- - '>='
|
39
104
|
- !ruby/object:Gem::Version
|
40
105
|
version: '0'
|
41
|
-
none: false
|
42
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
107
|
requirements:
|
44
|
-
- -
|
108
|
+
- - '>'
|
45
109
|
- !ruby/object:Gem::Version
|
46
110
|
version: 1.3.1
|
47
|
-
none: false
|
48
111
|
requirements: []
|
49
112
|
rubyforge_project:
|
50
|
-
rubygems_version:
|
113
|
+
rubygems_version: 2.0.3
|
51
114
|
signing_key:
|
52
|
-
specification_version:
|
53
|
-
summary: its
|
54
|
-
test_files:
|
55
|
-
|
115
|
+
specification_version: 4
|
116
|
+
summary: Provides "its" method formally part of rspec-core
|
117
|
+
test_files:
|
118
|
+
- features/its.feature
|
119
|
+
- features/step_definitions/additional_cli_steps.rb
|
120
|
+
- features/support/env.rb
|
121
|
+
- spec/rspec/its_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
data/lib/rspec-its.rb
DELETED