rspec-its 1.3.1 → 2.0.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 +4 -4
- data/.github/workflows/ci.yml +25 -87
- data/.gitignore +1 -0
- data/.rubocop.yml +46 -0
- data/Changelog.md +9 -0
- data/Gemfile +14 -25
- data/LICENSE.txt +1 -1
- data/README.md +12 -14
- data/Rakefile +3 -1
- data/features/its.feature +31 -59
- data/features/step_definitions/additional_cli_steps.rb +14 -12
- data/features/support/env.rb +9 -10
- data/lib/rspec/its/subject.rb +26 -0
- data/lib/rspec/its/version.rb +3 -1
- data/lib/rspec/its.rb +48 -59
- data/rspec-its.gemspec +16 -34
- data/script/test_all +6 -8
- data/script/update_rubygems_and_install_bundler +3 -31
- data/spec/rspec/its_spec.rb +333 -303
- data/spec/spec_helper.rb +8 -1
- metadata +17 -79
- data/script/legacy_setup.sh +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d1e500e46f3ca1f648ee76288e9ac19340ee6dfb42ac9f0714534f71fab3a46
|
4
|
+
data.tar.gz: 0f5b92bf819bf9c825e0776a8f4b53dcce9566db785188ae6b349a05b9afbd5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fd88f4645fb0c2b3a81cca6fba3abdcee34eb50526af38a5a30d896e17d272756744bf0d2009b4862b4e9acc3d697855ba72370e88b8d02e593e87395f923bb
|
7
|
+
data.tar.gz: 27af6704b1e805eb8eebbd91797ee29c44f006384e0289c0526d92aafe07f06c613ac655551dac326049d105ddfb6876bcd110c844b87454d028ea8a04383e8c
|
data/.github/workflows/ci.yml
CHANGED
@@ -9,86 +9,51 @@ on:
|
|
9
9
|
branches:
|
10
10
|
- '*'
|
11
11
|
env:
|
12
|
-
BRANCH: '3-12-maintenance'
|
13
12
|
RSPEC_CI: true
|
14
13
|
jobs:
|
14
|
+
rubocop:
|
15
|
+
name: Rubocop
|
16
|
+
runs-on: 'ubuntu-20.04'
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v4
|
19
|
+
- uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: '3.3'
|
22
|
+
- run: script/update_rubygems_and_install_bundler
|
23
|
+
- run: bundle install
|
24
|
+
- run: bundle exec rubocop -c .rubocop.yml
|
25
|
+
|
15
26
|
test:
|
16
27
|
name: Ruby ${{ matrix.ruby }} ${{ matrix.name_extra || '' }}
|
17
28
|
runs-on: ${{ matrix.os || 'ubuntu-20.04' }}
|
18
29
|
strategy:
|
19
30
|
matrix:
|
20
31
|
ruby:
|
32
|
+
- '3.4'
|
33
|
+
- '3.3'
|
21
34
|
- '3.2'
|
22
35
|
- '3.1'
|
23
36
|
- '3.0'
|
24
|
-
- 2.7
|
25
|
-
- 2.6
|
26
|
-
- 2.5
|
27
|
-
- 2.4
|
28
|
-
- 2.3
|
29
|
-
- 2.2
|
30
|
-
- 2.1.9
|
31
37
|
env:
|
32
38
|
-
|
33
39
|
BRANCH: "main"
|
34
40
|
include:
|
35
|
-
- ruby:
|
41
|
+
- ruby: '3.3'
|
42
|
+
name_extra: "against RSpec 3.13"
|
36
43
|
env:
|
37
|
-
|
38
|
-
# Compatibility builds
|
44
|
+
BRANCH: "3-13-maintenance"
|
39
45
|
- ruby: '3.2'
|
40
|
-
name_extra: "against RSpec 3.
|
46
|
+
name_extra: "against RSpec 3.13"
|
41
47
|
env:
|
42
|
-
BRANCH: "3-
|
48
|
+
BRANCH: "3-13-maintenance"
|
43
49
|
- ruby: '3.1'
|
44
|
-
name_extra: "against RSpec 3.
|
45
|
-
env:
|
46
|
-
BRANCH: "3-11-maintenance"
|
47
|
-
- ruby: '3.1'
|
48
|
-
name_extra: "against RSpec 3.10"
|
49
|
-
env:
|
50
|
-
BRANCH: "3-10-maintenance"
|
51
|
-
- ruby: '3.0'
|
52
|
-
name_extra: "against RSpec 3.9"
|
53
|
-
env:
|
54
|
-
BRANCH: "3-9-maintenance"
|
55
|
-
- ruby: '3.0'
|
56
|
-
name_extra: "against RSpec 3.8"
|
57
|
-
env:
|
58
|
-
BRANCH: "3-8-maintenance"
|
59
|
-
- ruby: '3.0'
|
60
|
-
name_extra: "against RSpec 3.7"
|
61
|
-
env:
|
62
|
-
BRANCH: "3-7-maintenance"
|
63
|
-
- ruby: '3.0'
|
64
|
-
name_extra: "against RSpec 3.6"
|
65
|
-
env:
|
66
|
-
BRANCH: "3-6-maintenance"
|
67
|
-
- ruby: '3.0'
|
68
|
-
name_extra: "against RSpec 3.5"
|
50
|
+
name_extra: "against RSpec 3.13"
|
69
51
|
env:
|
70
|
-
BRANCH: "3-
|
52
|
+
BRANCH: "3-13-maintenance"
|
71
53
|
- ruby: '3.0'
|
72
|
-
name_extra: "against RSpec 3.
|
54
|
+
name_extra: "against RSpec 3.13"
|
73
55
|
env:
|
74
|
-
BRANCH: "3-
|
75
|
-
- ruby: '3.0'
|
76
|
-
name_extra: "against RSpec 3.3"
|
77
|
-
env:
|
78
|
-
BRANCH: "3-3-maintenance"
|
79
|
-
- ruby: '3.0'
|
80
|
-
name_extra: "against RSpec 3.2"
|
81
|
-
env:
|
82
|
-
BRANCH: "3-2-maintenance"
|
83
|
-
- ruby: '3.0'
|
84
|
-
name_extra: "against RSpec 3.1"
|
85
|
-
env:
|
86
|
-
BRANCH: "3-1-maintenance"
|
87
|
-
- ruby: '3.0'
|
88
|
-
name_extra: "against RSpec 3.0"
|
89
|
-
env:
|
90
|
-
BRANCH: "3-0-maintenance"
|
91
|
-
|
56
|
+
BRANCH: "3-13-maintenance"
|
92
57
|
fail-fast: false
|
93
58
|
continue-on-error: ${{ matrix.allow_failure || endsWith(matrix.ruby, 'head') }}
|
94
59
|
env: ${{ matrix.env }}
|
@@ -99,33 +64,6 @@ jobs:
|
|
99
64
|
bundler: ${{ matrix.bundler || 2 }}
|
100
65
|
ruby-version: ${{ matrix.ruby }}
|
101
66
|
- run: script/update_rubygems_and_install_bundler
|
102
|
-
- run: bundle install --
|
103
|
-
- run:
|
104
|
-
|
105
|
-
legacy:
|
106
|
-
name: Legacy Ruby Builds (${{ matrix.container.version }})
|
107
|
-
runs-on: ubuntu-20.04
|
108
|
-
container:
|
109
|
-
image: ${{ matrix.container.tag }}
|
110
|
-
options: ${{ matrix.container.options || '--add-host github-complains-if-this-is-empty.com:127.0.0.1' }}
|
111
|
-
strategy:
|
112
|
-
fail-fast: false
|
113
|
-
matrix:
|
114
|
-
container:
|
115
|
-
- version: "2.0"
|
116
|
-
tag: ghcr.io/rspec/docker-ci:2.0.0
|
117
|
-
- version: "1.9.3"
|
118
|
-
tag: ghcr.io/rspec/docker-ci:1.9.3
|
119
|
-
- version: "JRuby 1.7"
|
120
|
-
tag: ghcr.io/rspec/docker-ci:jruby-1.7
|
121
|
-
- version: "JRuby 9.1.17.0"
|
122
|
-
tag: ghcr.io/rspec/docker-ci:jruby-9.1.17.0
|
123
|
-
options: "--add-host rubygems.org:151.101.129.227 --add-host api.rubygems.org:151.101.129.227"
|
124
|
-
env:
|
125
|
-
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
|
126
|
-
LEGACY_CI: true
|
127
|
-
JRUBY_OPTS: ${{ matrix.container.jruby_opts || '--dev' }}
|
128
|
-
steps:
|
129
|
-
- uses: actions/checkout@v3
|
130
|
-
- run: script/legacy_setup.sh
|
67
|
+
- run: bundle install --standalone
|
68
|
+
- run: bundle binstubs --all
|
131
69
|
- run: script/test_all
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
SuggestExtensions: false
|
4
|
+
|
5
|
+
Metrics/BlockLength:
|
6
|
+
Enabled: true
|
7
|
+
Exclude:
|
8
|
+
- spec/**/*_spec.rb
|
9
|
+
|
10
|
+
Layout/LineLength:
|
11
|
+
Max: 120
|
12
|
+
|
13
|
+
Lint/NestedMethodDefinition:
|
14
|
+
Exclude:
|
15
|
+
- lib/rspec/its.rb
|
16
|
+
|
17
|
+
Lint/SendWithMixinArgument:
|
18
|
+
Exclude:
|
19
|
+
- lib/rspec/its.rb
|
20
|
+
|
21
|
+
Metrics/AbcSize:
|
22
|
+
Exclude:
|
23
|
+
- lib/rspec/its.rb
|
24
|
+
|
25
|
+
Metrics/MethodLength:
|
26
|
+
Max: 25
|
27
|
+
|
28
|
+
Naming/PredicateName:
|
29
|
+
Exclude:
|
30
|
+
- lib/rspec/its.rb
|
31
|
+
|
32
|
+
Style/CaseEquality:
|
33
|
+
Exclude:
|
34
|
+
- lib/rspec/its/subject.rb
|
35
|
+
|
36
|
+
Style/SignalException:
|
37
|
+
Exclude:
|
38
|
+
- features/**/*.rb
|
39
|
+
|
40
|
+
Style/SpecialGlobalVars:
|
41
|
+
Exclude:
|
42
|
+
- rspec-its.gemspec
|
43
|
+
|
44
|
+
# We don't care about single vs double quotes.
|
45
|
+
Style/StringLiterals:
|
46
|
+
Enabled: false
|
data/Changelog.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
### 2.0.0 / 2024-11-04
|
2
|
+
|
3
|
+
Version 2.0.0 drops support for Ruby below 3, and changes the supported RSpec version to "main" and current release series.
|
4
|
+
(At the time of writing this is 3.13.x, but it means the current supported release only).
|
5
|
+
|
6
|
+
Breaking changes:
|
7
|
+
|
8
|
+
* Now uses `public_send` so that private methods will not be accidentally reachable. (James Ottaway #33, #101)
|
9
|
+
|
1
10
|
### 1.3.1 / 2024-10-23
|
2
11
|
[full changelog](http://github.com/rspec/rspec-its/compare/v1.3.0...v1.3.1)
|
3
12
|
|
data/Gemfile
CHANGED
@@ -1,38 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
|
-
# Specify your gem's dependencies in rspec-its.gemspec
|
4
5
|
gemspec
|
5
6
|
|
6
7
|
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
|
7
|
-
branch = ENV.fetch('BRANCH','main')
|
8
|
+
branch = ENV.fetch('BRANCH', 'main')
|
8
9
|
library_path = File.expand_path("../../#{lib}", __FILE__)
|
9
10
|
|
10
11
|
if File.exist?(library_path) && !ENV['USE_GIT_REPOS']
|
11
|
-
gem lib, :
|
12
|
+
gem lib, path: library_path
|
12
13
|
elsif lib == 'rspec'
|
13
|
-
gem 'rspec', :
|
14
|
+
gem 'rspec', git: "https://github.com/rspec/rspec-metagem.git", branch: branch
|
14
15
|
else
|
15
|
-
gem lib, :
|
16
|
+
gem lib, git: "https://github.com/rspec/#{lib}.git", branch: branch
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
else
|
28
|
-
gem 'ffi', '~> 1.15.0'
|
29
|
-
end
|
30
|
-
|
31
|
-
# test coverage
|
32
|
-
# gem 'simplecov', :require => false
|
33
|
-
|
34
|
-
gem 'contracts', '< 0.16' if RUBY_VERSION < '1.9.0'
|
35
|
-
|
36
|
-
gem 'coveralls', :require => false, :platform => :mri_20
|
37
|
-
|
38
|
-
eval File.read('Gemfile-custom') if File.exist?('Gemfile-custom')
|
20
|
+
gem 'aruba', '~> 2.2.0'
|
21
|
+
gem 'bundler', '> 2.0.0'
|
22
|
+
gem 'coveralls', require: false
|
23
|
+
gem 'cucumber', '>= 1.3.8'
|
24
|
+
gem 'ffi', '~> 1.17.0'
|
25
|
+
gem 'matrix', '~> 0.4.2'
|
26
|
+
gem 'rake', '~> 13.2.0'
|
27
|
+
gem 'rubocop', '~> 1.68.0'
|
data/LICENSE.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
(The MIT License)
|
2
2
|
|
3
|
+
Copyright (c) 2024 The RSpec Development Team
|
3
4
|
Copyright (c) 2013 Peter Alfvin
|
4
5
|
Copyright (c) 2012 David Chelimsky, Myron Marston
|
5
6
|
Copyright (c) 2006 David Chelimsky, The RSpec Development Team
|
6
|
-
Copyright (c) 2005 Steven Baker
|
7
7
|
|
8
8
|
MIT License
|
9
9
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# RSpec::Its [](https://github.com/rspec/rspec-its/actions/workflows/ci.yml/badge.svg)
|
2
2
|
|
3
3
|
RSpec::Its provides the `its` method as a short-hand to specify the expected value of an attribute.
|
4
4
|
|
@@ -26,33 +26,31 @@ require 'rspec/its'
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
Use the `its` method to generate a nested example group with
|
30
|
-
|
31
|
-
subject using `
|
32
|
-
The `its` method can also specify the block expectations of an attribute of the
|
33
|
-
subject using `will` or `will_not`.
|
29
|
+
Use the `its` method to generate a nested example group with a single example that specifies the expected value
|
30
|
+
of an attribute of the subject using `is_expected`. The `its` method can also specify the block expectations of
|
31
|
+
an attribute of the subject using `will` or `will_not`.
|
34
32
|
|
35
33
|
`its` accepts a symbol or a string, and a block representing the example.
|
36
34
|
|
37
35
|
```ruby
|
38
|
-
its(:size) {
|
39
|
-
its("length") {
|
36
|
+
its(:size) { is_expected.to eq(1) }
|
37
|
+
its("length") { is_expected.to eq(1) }
|
40
38
|
```
|
41
39
|
|
42
40
|
You can use a string with dots to specify a nested attribute (i.e. an
|
43
41
|
attribute of the attribute of the subject).
|
44
42
|
|
45
43
|
```ruby
|
46
|
-
its("phone_numbers.size") {
|
44
|
+
its("phone_numbers.size") { is_expected.to_not eq(0) }
|
47
45
|
```
|
48
46
|
|
49
|
-
The following
|
47
|
+
The following should-style method is also available:
|
50
48
|
|
51
49
|
```ruby
|
52
|
-
its(:size) {
|
50
|
+
its(:size) { should eq(1) }
|
53
51
|
```
|
54
52
|
|
55
|
-
as is
|
53
|
+
as is an alias of `is_expected` for pluralized use:
|
56
54
|
|
57
55
|
```ruby
|
58
56
|
its(:keys) { are_expected.to eq([:key1, :key2]) }
|
@@ -88,13 +86,13 @@ For other objects, multiple keys within the array will be passed as separate arg
|
|
88
86
|
|
89
87
|
```ruby
|
90
88
|
subject { Matrix[ [:a, :b], [:c, :d] ] }
|
91
|
-
its([1,1]) {
|
89
|
+
its([1,1]) { is_expected.to eq(:d) }
|
92
90
|
```
|
93
91
|
|
94
92
|
Metadata arguments are supported.
|
95
93
|
|
96
94
|
```ruby
|
97
|
-
its(:size, focus: true) {
|
95
|
+
its(:size, focus: true) { is_expected.to eq(1) }
|
98
96
|
```
|
99
97
|
|
100
98
|
## Contributing
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bundler"
|
2
4
|
Bundler.setup
|
3
5
|
Bundler::GemHelper.install_tasks
|
@@ -13,4 +15,4 @@ RSpec::Core::RakeTask.new(:spec) do |t|
|
|
13
15
|
t.ruby_opts = %w[-w]
|
14
16
|
end
|
15
17
|
|
16
|
-
task :
|
18
|
+
task default: %i[spec cucumber]
|
data/features/its.feature
CHANGED
@@ -1,57 +1,25 @@
|
|
1
1
|
Feature: attribute of subject
|
2
2
|
|
3
|
-
@pre-3-9
|
4
3
|
Scenario: specify value of a nested attribute
|
5
4
|
Given a file named "example_spec.rb" with:
|
6
5
|
"""ruby
|
7
6
|
class Person
|
8
7
|
attr_reader :phone_numbers
|
9
|
-
def initialize
|
10
|
-
@phone_numbers = []
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe Person do
|
15
|
-
context "with one phone number (555-1212)"do
|
16
|
-
subject do
|
17
|
-
person = Person.new
|
18
|
-
person.phone_numbers << "555-1212"
|
19
|
-
person
|
20
|
-
end
|
21
|
-
|
22
|
-
its("phone_numbers.first") { should eq("555-1212") }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
"""
|
26
|
-
When I run rspec with the documentation option
|
27
|
-
Then the output should contain:
|
28
|
-
"""
|
29
|
-
Person
|
30
|
-
with one phone number (555-1212)
|
31
|
-
phone_numbers.first
|
32
|
-
should eq "555-1212"
|
33
|
-
"""
|
34
8
|
|
35
|
-
@post-3-9
|
36
|
-
Scenario: specify value of a nested attribute
|
37
|
-
Given a file named "example_spec.rb" with:
|
38
|
-
"""ruby
|
39
|
-
class Person
|
40
|
-
attr_reader :phone_numbers
|
41
9
|
def initialize
|
42
10
|
@phone_numbers = []
|
43
11
|
end
|
44
12
|
end
|
45
13
|
|
46
|
-
describe Person do
|
14
|
+
RSpec.describe Person do
|
47
15
|
context "with one phone number (555-1212)"do
|
48
|
-
subject do
|
16
|
+
subject(:person) do
|
49
17
|
person = Person.new
|
50
18
|
person.phone_numbers << "555-1212"
|
51
19
|
person
|
52
20
|
end
|
53
21
|
|
54
|
-
its("phone_numbers.first") {
|
22
|
+
its("phone_numbers.first") { is_expected.to eq("555-1212") }
|
55
23
|
end
|
56
24
|
end
|
57
25
|
"""
|
@@ -67,13 +35,13 @@ Feature: attribute of subject
|
|
67
35
|
Scenario: specify value of an attribute of a hash
|
68
36
|
Given a file named "example_spec.rb" with:
|
69
37
|
"""ruby
|
70
|
-
describe Hash do
|
38
|
+
RSpec.describe Hash do
|
71
39
|
context "with two items" do
|
72
40
|
subject do
|
73
41
|
{:one => 'one', :two => 'two'}
|
74
42
|
end
|
75
43
|
|
76
|
-
its(:size) {
|
44
|
+
its(:size) { is_expected.to eq(2) }
|
77
45
|
end
|
78
46
|
end
|
79
47
|
"""
|
@@ -83,14 +51,14 @@ Feature: attribute of subject
|
|
83
51
|
Scenario: specify value for key in a hash
|
84
52
|
Given a file named "example_spec.rb" with:
|
85
53
|
"""ruby
|
86
|
-
describe Hash do
|
54
|
+
RSpec.describe Hash do
|
87
55
|
context "with keys :one and 'two'" do
|
88
56
|
subject do
|
89
57
|
{:one => 1, "two" => 2}
|
90
58
|
end
|
91
59
|
|
92
|
-
its([:one]) {
|
93
|
-
its(["two"]) {
|
60
|
+
its([:one]) { is_expected.to eq(1) }
|
61
|
+
its(["two"]) { is_expected.to eq(2) }
|
94
62
|
end
|
95
63
|
end
|
96
64
|
"""
|
@@ -102,15 +70,15 @@ Feature: attribute of subject
|
|
102
70
|
"""ruby
|
103
71
|
require 'matrix'
|
104
72
|
|
105
|
-
describe Matrix do
|
73
|
+
RSpec.describe Matrix do
|
106
74
|
context "with values [[1, 2], [3, 4]]" do
|
107
75
|
subject do
|
108
76
|
Matrix[[1, 2], [3, 4]]
|
109
77
|
end
|
110
78
|
|
111
|
-
its([0, 1]) {
|
112
|
-
its([1, 0]) {
|
113
|
-
its([1, 2]) {
|
79
|
+
its([0, 1]) { are_expected.to eq(2) }
|
80
|
+
its([1, 0]) { are_expected.to eq(3) }
|
81
|
+
its([1, 2]) { are_expected.to be_nil }
|
114
82
|
end
|
115
83
|
end
|
116
84
|
"""
|
@@ -120,22 +88,22 @@ Feature: attribute of subject
|
|
120
88
|
Scenario: failures are correctly reported as coming from the `its` line
|
121
89
|
Given a file named "example_spec.rb" with:
|
122
90
|
"""ruby
|
123
|
-
describe Array do
|
91
|
+
RSpec.describe Array do
|
124
92
|
context "when first created" do
|
125
|
-
its(:size) {
|
93
|
+
its(:size) { is_expected.to_not eq(0) }
|
126
94
|
end
|
127
95
|
end
|
128
96
|
"""
|
129
97
|
When I run rspec
|
130
|
-
Then the output should contain "Failure/Error: its(:size) {
|
131
|
-
|
98
|
+
Then the output should contain "Failure/Error: its(:size) { is_expected.to_not eq(0) }"
|
99
|
+
And the output should not match /#[^\n]*rspec[\x2f]its/
|
132
100
|
|
133
101
|
Scenario: examples can be specified by exact line number
|
134
102
|
Given a file named "example_spec.rb" with:
|
135
103
|
"""ruby
|
136
|
-
describe Array do
|
104
|
+
RSpec.describe Array do
|
137
105
|
context "when first created" do
|
138
|
-
its(:size) {
|
106
|
+
its(:size) { is_expected.to eq(0) }
|
139
107
|
end
|
140
108
|
end
|
141
109
|
"""
|
@@ -145,10 +113,11 @@ Feature: attribute of subject
|
|
145
113
|
Scenario: examples can be specified by line number within containing block
|
146
114
|
Given a file named "example_spec.rb" with:
|
147
115
|
"""ruby
|
148
|
-
describe Array do
|
116
|
+
RSpec.describe Array do
|
149
117
|
context "when first created" do
|
150
|
-
its(:size) {
|
118
|
+
its(:size) { is_expected.to eq(0) }
|
151
119
|
end
|
120
|
+
|
152
121
|
it "should never execute this" do
|
153
122
|
expect(true).to be(false)
|
154
123
|
end
|
@@ -166,8 +135,9 @@ Feature: attribute of subject
|
|
166
135
|
end
|
167
136
|
end
|
168
137
|
|
169
|
-
describe Klass do
|
170
|
-
subject { Klass.new }
|
138
|
+
RSpec.describe Klass do
|
139
|
+
subject(:klass) { Klass.new }
|
140
|
+
|
171
141
|
its(:foo) { will_not raise_error }
|
172
142
|
its(:bar) { will raise_error(NoMethodError) }
|
173
143
|
end
|
@@ -180,15 +150,16 @@ Feature: attribute of subject
|
|
180
150
|
"""ruby
|
181
151
|
class Klass; end
|
182
152
|
|
183
|
-
describe Klass do
|
184
|
-
subject { Klass.new }
|
153
|
+
RSpec.describe Klass do
|
154
|
+
subject(:klass) { Klass.new }
|
155
|
+
|
185
156
|
its(:foo) { will_not raise_error }
|
186
157
|
end
|
187
158
|
"""
|
188
159
|
When I run rspec
|
189
160
|
Then the example should fail
|
190
161
|
And the output should contain "Failure/Error: its(:foo) { will_not raise_error }"
|
191
|
-
And the output should
|
162
|
+
And the output should match /expected no Exception, got #<NoMethodError: undefined method [`']foo'/
|
192
163
|
|
193
164
|
Scenario: examples will warn when using non block expectations
|
194
165
|
Given a file named "example_spec.rb" with:
|
@@ -199,8 +170,9 @@ Feature: attribute of subject
|
|
199
170
|
end
|
200
171
|
end
|
201
172
|
|
202
|
-
describe Klass do
|
203
|
-
subject { Klass.new }
|
173
|
+
RSpec.describe Klass do
|
174
|
+
subject(:arnie) { Klass.new }
|
175
|
+
|
204
176
|
its(:terminator) { will be("back") }
|
205
177
|
end
|
206
178
|
"""
|
@@ -1,32 +1,34 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
When(/^I run rspec( with the documentation option)?$/) do |documentation|
|
4
|
+
rspec_its_gem_location = File.expand_path('../../lib/rspec/its', __dir__)
|
3
5
|
require_option = "--require #{rspec_its_gem_location}"
|
4
6
|
format_option = documentation ? "--format documentation" : ""
|
5
7
|
rspec_command = ['rspec', require_option, format_option, 'example_spec.rb'].join(' ')
|
6
8
|
step "I run `#{rspec_command}`"
|
7
9
|
end
|
8
10
|
|
9
|
-
When
|
10
|
-
rspec_its_gem_location = File.expand_path('
|
11
|
+
When(/^I run rspec specifying line number (\d+)$/) do |line_number|
|
12
|
+
rspec_its_gem_location = File.expand_path('../../lib/rspec/its', __dir__)
|
11
13
|
require_option = "--require #{rspec_its_gem_location}"
|
12
14
|
file_specification = "example_spec.rb:#{line_number}"
|
13
15
|
rspec_command = ['rspec', require_option, file_specification].join(' ')
|
14
16
|
step "I run `#{rspec_command}`"
|
15
17
|
end
|
16
18
|
|
17
|
-
Then
|
18
|
-
step
|
19
|
-
step
|
20
|
-
step
|
19
|
+
Then(/^the example(?:s)? should(?: all)? pass$/) do
|
20
|
+
step 'the output should contain "0 failures"'
|
21
|
+
step 'the output should not contain "0 examples"'
|
22
|
+
step 'the exit status should be 0'
|
21
23
|
end
|
22
24
|
|
23
|
-
Then(
|
24
|
-
step
|
25
|
-
step
|
25
|
+
Then("the example should fail") do
|
26
|
+
step 'the output should contain "1 failure"'
|
27
|
+
step 'the exit status should not be 0'
|
26
28
|
end
|
27
29
|
|
28
30
|
Then(/^the output should contain "(.*?)" and "(.*?)"$/) do |string1, string2|
|
29
31
|
unless [string1, string2].all? { |s| all_output.include?(s) }
|
30
|
-
fail %
|
32
|
+
fail %(Both "#{string1}" and "#{string2}" were found in:\n#{all_output})
|
31
33
|
end
|
32
34
|
end
|
data/features/support/env.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'aruba/cucumber'
|
2
4
|
require 'rspec/core'
|
3
5
|
require 'rspec/its'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
Aruba.configure do |config|
|
12
|
-
config.before(:command) do |cmd|
|
13
|
-
cmd.environment['RBXOPT'] = "-Xint=true #{ENV['RBXOPT']}" # disable JIT since these processes are so short lived
|
7
|
+
if RUBY_PLATFORM == 'java'
|
8
|
+
Aruba.configure do |config|
|
9
|
+
config.before(:command) do |cmd|
|
10
|
+
# disable JIT since these processes are so short lived
|
11
|
+
cmd.environment['JRUBY_OPTS'] = "-X-C #{ENV.fetch('JRUBY_OPTS', '')}"
|
12
|
+
end
|
14
13
|
end
|
15
|
-
end
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Its
|
5
|
+
# @api private
|
6
|
+
# Handles turning subject into an expectation target
|
7
|
+
module Subject
|
8
|
+
def for(attribute, subject)
|
9
|
+
if Array === attribute
|
10
|
+
if Hash === subject
|
11
|
+
attribute.inject(subject) { |inner, attr| inner[attr] }
|
12
|
+
else
|
13
|
+
subject[*attribute]
|
14
|
+
end
|
15
|
+
else
|
16
|
+
attribute_chain = attribute.to_s.split('.')
|
17
|
+
attribute_chain.inject(subject) do |inner_subject, attr|
|
18
|
+
inner_subject.public_send(attr)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module_function :for
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|