rspec-expect_it 1.1.0 → 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/.rspec +1 -1
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/Gemfile +6 -1
- data/Guardfile +5 -0
- data/README.md +8 -28
- data/lib/rspec/expect_it.rb +2 -0
- data/lib/rspec/expect_it/expectation_targets/expect_it.rb +28 -0
- data/lib/rspec/expect_it/expectation_targets/expect_its.rb +20 -0
- data/lib/rspec/expect_it/helpers.rb +5 -65
- data/lib/rspec/expect_it/version.rb +1 -1
- data/rspec-expect_it.gemspec +1 -1
- data/spec/rspec/expect_it/expectation_targets/expect_it_spec.rb +42 -0
- data/spec/rspec/expect_it/expectation_targets/expect_its_spec.rb +29 -0
- data/spec/rspec/expect_it/helpers_spec.rb +2 -40
- metadata +26 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0aa79562e13f859d4812639821f2e31652dc826
|
4
|
+
data.tar.gz: 634f4d65356c1068afdd3967839433380f05bfc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cf5c066d0d079cbbd9d5332fcfd765e235b007066a85a92074e6277f94553431c0c3978f427761015a402ed7b2748a1f905c22a0f45b1d4b6ef147f2872fcef
|
7
|
+
data.tar.gz: 159feba7f88dbd388a0fced4692acc4ef4b4e9c188881f06292bab07440c79701ceea11cb48690d03850c0ab86320462a5356e98f8dde8176d0699f3ae301b65
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
--color
|
2
|
-
--format
|
2
|
+
--format Fuubar
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.1.0
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# RSpec::ExpectIt
|
2
2
|
|
3
|
-
[](https://travis-ci.org/thomasfedb/rspec-expect_it)
|
3
|
+
[](https://travis-ci.org/thomasfedb/rspec-expect_it)
|
4
|
+
[](http://badge.fury.io/rb/rspec-expect_it)
|
5
|
+
[](https://codeclimate.com/github/thomasfedb/rspec-expect_it)
|
4
6
|
|
5
|
-
Makes writing nice RSpec tests a little easier by providing expect_it helpers.
|
7
|
+
Makes writing nice RSpec tests a little easier by providing `expect_it` helpers.
|
8
|
+
These helpers are equivalent to `expect(subject)` and also provide useful variations.
|
6
9
|
|
7
10
|
Compatible with Ruby 1.9.2 and greater.
|
8
11
|
|
@@ -63,7 +66,6 @@ specify { expect_it{}.to change{@value}.by(1) }
|
|
63
66
|
### expect_its
|
64
67
|
|
65
68
|
Calling `expect_its(:method)` is equivalent to `expect(subject.method)`.
|
66
|
-
There is no `_safe` version of this helper.
|
67
69
|
|
68
70
|
```ruby
|
69
71
|
subject { "foobar" }
|
@@ -74,7 +76,6 @@ specify { expect_its(:length).to eq 6 }
|
|
74
76
|
### expect_its!
|
75
77
|
|
76
78
|
If you want eager evaluation of the subject and method call, use `expect_its!`.
|
77
|
-
There is no `_safe` version of this helper.
|
78
79
|
|
79
80
|
```ruby
|
80
81
|
subject { @value += 1 }
|
@@ -82,32 +83,11 @@ subject { @value += 1 }
|
|
82
83
|
specify { expect_its!(:to_s).to eq @value.to_s }
|
83
84
|
```
|
84
85
|
|
85
|
-
### expect_it_safe
|
86
|
-
|
87
|
-
The `expect_it_safe` helper is the same as `expect_it`, except that it will
|
88
|
-
swallow any exceptions and return `nil`.
|
89
|
-
|
90
|
-
```ruby
|
91
|
-
subject { raise Exception }
|
92
|
-
|
93
|
-
specify { expect_it_safe.to eq nil }
|
94
|
-
```
|
95
|
-
|
96
|
-
### expect_it_safe!
|
97
|
-
|
98
|
-
The `expect_it_safe!` helper is the same as `expect_it!`, except that it will
|
99
|
-
swallow any exceptions and return `nil`.
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
subject { raise Exception }
|
103
|
-
|
104
|
-
specify { expect_it_safe!.to eq nil }
|
105
|
-
```
|
106
|
-
|
107
86
|
### expect_it_safe{}
|
108
87
|
|
109
88
|
The `expect_it_safe{}` helper is the same as `expect_it{}`, except that it will
|
110
|
-
swallow any exceptions
|
89
|
+
swallow any exceptions. This can be helpful when checking that error scenarios
|
90
|
+
do not lead to changes that should only occur when the system is successful.
|
111
91
|
|
112
92
|
```ruby
|
113
93
|
subject { raise Exception; @value = 12 }
|
@@ -122,4 +102,4 @@ specify { expect_it_safe{}.to_not change{@value} }
|
|
122
102
|
3. Add your feature and specs.
|
123
103
|
4. Commit your changes (`git commit -am 'Add some feature'`)
|
124
104
|
5. Push to the branch (`git push origin my-new-feature`)
|
125
|
-
6. Create new Pull Request
|
105
|
+
6. Create new Pull Request
|
data/lib/rspec/expect_it.rb
CHANGED
@@ -2,6 +2,8 @@ require "rspec"
|
|
2
2
|
|
3
3
|
require "rspec/expect_it/version"
|
4
4
|
require "rspec/expect_it/helpers"
|
5
|
+
require "rspec/expect_it/expectation_targets/expect_it"
|
6
|
+
require "rspec/expect_it/expectation_targets/expect_its"
|
5
7
|
|
6
8
|
RSpec.configure do |config|
|
7
9
|
config.include RSpec::ExpectIt::Helpers
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RSpec
|
2
|
+
module ExpectIt
|
3
|
+
module ExpectationTargets
|
4
|
+
class ExpectIt
|
5
|
+
attr_accessor :context, :subject
|
6
|
+
|
7
|
+
def initialize(context, subject = nil)
|
8
|
+
self.context = context
|
9
|
+
self.subject = subject
|
10
|
+
end
|
11
|
+
|
12
|
+
def to(matcher)
|
13
|
+
context.expect(get_subject).to(matcher)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_not(matcher)
|
17
|
+
context.expect(get_subject).to_not(matcher)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def get_subject
|
23
|
+
subject || context.subject
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module RSpec
|
2
|
+
module ExpectIt
|
3
|
+
module ExpectationTargets
|
4
|
+
class ExpectIts < ExpectIt
|
5
|
+
attr_accessor :method
|
6
|
+
|
7
|
+
def initialize(context, method)
|
8
|
+
super(context)
|
9
|
+
self.method = method
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def get_subject
|
15
|
+
context.subject.send(method)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -3,9 +3,9 @@ module RSpec
|
|
3
3
|
module Helpers
|
4
4
|
def expect_it
|
5
5
|
if block_given?
|
6
|
-
|
6
|
+
RSpec::ExpectIt::ExpectationTargets::ExpectIt.new(self, lambda { self.subject })
|
7
7
|
else
|
8
|
-
|
8
|
+
RSpec::ExpectIt::ExpectationTargets::ExpectIt.new(self)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -14,7 +14,7 @@ module RSpec
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def expect_its(method)
|
17
|
-
|
17
|
+
RSpec::ExpectIt::ExpectationTargets::ExpectIts.new(self, method)
|
18
18
|
end
|
19
19
|
|
20
20
|
def expect_its!(method)
|
@@ -30,69 +30,9 @@ module RSpec
|
|
30
30
|
nil
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
RSpec::ExpectIt::ExpectationTargets::ExpectIt.new(self, safe_lambda)
|
34
34
|
else
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def expect_it_safe!
|
40
|
-
result = begin
|
41
|
-
self.subject
|
42
|
-
rescue Exception
|
43
|
-
nil
|
44
|
-
end
|
45
|
-
|
46
|
-
expect(result)
|
47
|
-
end
|
48
|
-
|
49
|
-
class ExpectItExpectationTarget
|
50
|
-
attr_accessor :context, :subject
|
51
|
-
|
52
|
-
def initialize(context, subject = nil)
|
53
|
-
self.context = context
|
54
|
-
self.subject = subject
|
55
|
-
end
|
56
|
-
|
57
|
-
def to(matcher)
|
58
|
-
context.expect(get_subject).to(matcher)
|
59
|
-
end
|
60
|
-
|
61
|
-
def to_not(matcher)
|
62
|
-
context.expect(get_subject).to_not(matcher)
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def get_subject
|
68
|
-
subject || context.subject
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
class ExpectItSafeExpectationTarget < ExpectItExpectationTarget
|
73
|
-
private
|
74
|
-
|
75
|
-
def get_subject
|
76
|
-
begin
|
77
|
-
subject || context.subject
|
78
|
-
rescue Exception
|
79
|
-
nil
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
class ExpectItsExpectationTarget < ExpectItExpectationTarget
|
85
|
-
attr_accessor :method
|
86
|
-
|
87
|
-
def initialize(context, method)
|
88
|
-
super(context)
|
89
|
-
self.method = method
|
90
|
-
end
|
91
|
-
|
92
|
-
private
|
93
|
-
|
94
|
-
def get_subject
|
95
|
-
context.subject.send(method)
|
35
|
+
raise ArgumentError, "method must be called as expect_it_safe{}"
|
96
36
|
end
|
97
37
|
end
|
98
38
|
end
|
data/rspec-expect_it.gemspec
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSpec::ExpectIt::ExpectationTargets::ExpectIt do
|
4
|
+
let(:context) do
|
5
|
+
double("context").tap do |context|
|
6
|
+
context.stub(:expect) {|arg| expect(arg) }
|
7
|
+
context.stub(:subject) { context_subject }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:passed_subject) { nil }
|
12
|
+
|
13
|
+
subject { RSpec::ExpectIt::ExpectationTargets::ExpectIt.new(context, passed_subject) }
|
14
|
+
|
15
|
+
describe "#to" do
|
16
|
+
context "when the subject is passed" do
|
17
|
+
let(:passed_subject) { Object.new }
|
18
|
+
|
19
|
+
specify { subject.to eq passed_subject }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when the subject is not passed" do
|
23
|
+
let(:context_subject) { Object.new }
|
24
|
+
|
25
|
+
specify { subject.to eq context_subject }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#not_to" do
|
30
|
+
context "when the subject is passed" do
|
31
|
+
let(:passed_subject) { Object.new }
|
32
|
+
|
33
|
+
specify { expect{ subject.to_not eq passed_subject }.to raise_error(RSpec::Expectations::ExpectationNotMetError) }
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when the subject is not passed" do
|
37
|
+
let(:context_subject) { Object.new }
|
38
|
+
|
39
|
+
specify { expect{ subject.to_not eq context_subject }.to raise_error(RSpec::Expectations::ExpectationNotMetError) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSpec::ExpectIt::ExpectationTargets::ExpectIts do
|
4
|
+
let(:context) do
|
5
|
+
double("context").tap do |context|
|
6
|
+
context.stub(:expect) {|arg| expect(arg) }
|
7
|
+
context.stub(:subject) { context_subject }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:context_subject) do
|
12
|
+
double("subject").tap do |subject|
|
13
|
+
subject.stub(method) { method_return_value }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:method) { :a_method }
|
18
|
+
let(:method_return_value) { Object.new }
|
19
|
+
|
20
|
+
subject { RSpec::ExpectIt::ExpectationTargets::ExpectIts.new(context, method) }
|
21
|
+
|
22
|
+
describe "#to" do
|
23
|
+
specify { subject.to eq method_return_value }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#not_to" do
|
27
|
+
specify { expect{ subject.to_not eq method_return_value }.to raise_error(RSpec::Expectations::ExpectationNotMetError) }
|
28
|
+
end
|
29
|
+
end
|
@@ -111,46 +111,8 @@ describe RSpec::ExpectIt::Helpers do
|
|
111
111
|
end
|
112
112
|
|
113
113
|
describe "expect_it_safe" do
|
114
|
-
describe "
|
115
|
-
|
116
|
-
|
117
|
-
specify { expect_it_safe.to eq subject }
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "lazy evaluation" do
|
121
|
-
before { @value = 0 }
|
122
|
-
|
123
|
-
subject { @value = 1 }
|
124
|
-
|
125
|
-
specify { expect_it_safe.to eq (@value + 1) }
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "saftey" do
|
129
|
-
subject { raise Exception }
|
130
|
-
|
131
|
-
specify { expect_it_safe.to eq nil }
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "expect_it_safe!" do
|
136
|
-
describe "equalivalence" do
|
137
|
-
subject { Object.new }
|
138
|
-
|
139
|
-
specify { expect_it_safe!.to eq subject }
|
140
|
-
end
|
141
|
-
|
142
|
-
describe "unlazy evaluation" do
|
143
|
-
before { @value = 0 }
|
144
|
-
|
145
|
-
subject { @value = 1 }
|
146
|
-
|
147
|
-
specify { expect_it_safe!.to eq @value }
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "saftey" do
|
151
|
-
subject { raise Exception }
|
152
|
-
|
153
|
-
specify { expect_it_safe!.to eq nil }
|
114
|
+
describe "not avaliable" do
|
115
|
+
specify { expect{ expect_it_safe }.to raise_error(ArgumentError) }
|
154
116
|
end
|
155
117
|
end
|
156
118
|
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-expect_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Drake-Brockman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.14.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
26
|
version: 2.14.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: fuubar
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Provides expect_it helpers for RSpec.
|
@@ -73,19 +73,24 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .rspec
|
78
|
-
- .ruby-gemset
|
79
|
-
- .ruby-version
|
80
|
-
- .travis.yml
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".ruby-gemset"
|
79
|
+
- ".ruby-version"
|
80
|
+
- ".travis.yml"
|
81
81
|
- Gemfile
|
82
|
+
- Guardfile
|
82
83
|
- LICENSE
|
83
84
|
- README.md
|
84
85
|
- Rakefile
|
85
86
|
- lib/rspec/expect_it.rb
|
87
|
+
- lib/rspec/expect_it/expectation_targets/expect_it.rb
|
88
|
+
- lib/rspec/expect_it/expectation_targets/expect_its.rb
|
86
89
|
- lib/rspec/expect_it/helpers.rb
|
87
90
|
- lib/rspec/expect_it/version.rb
|
88
91
|
- rspec-expect_it.gemspec
|
92
|
+
- spec/rspec/expect_it/expectation_targets/expect_it_spec.rb
|
93
|
+
- spec/rspec/expect_it/expectation_targets/expect_its_spec.rb
|
89
94
|
- spec/rspec/expect_it/helpers_spec.rb
|
90
95
|
- spec/spec_helper.rb
|
91
96
|
homepage: ''
|
@@ -98,20 +103,22 @@ require_paths:
|
|
98
103
|
- lib
|
99
104
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
105
|
requirements:
|
101
|
-
- -
|
106
|
+
- - ">="
|
102
107
|
- !ruby/object:Gem::Version
|
103
108
|
version: '0'
|
104
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
110
|
requirements:
|
106
|
-
- -
|
111
|
+
- - ">="
|
107
112
|
- !ruby/object:Gem::Version
|
108
113
|
version: '0'
|
109
114
|
requirements: []
|
110
115
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
116
|
+
rubygems_version: 2.2.0
|
112
117
|
signing_key:
|
113
118
|
specification_version: 4
|
114
119
|
summary: Provides a expect_it helpers for RSpec.
|
115
120
|
test_files:
|
121
|
+
- spec/rspec/expect_it/expectation_targets/expect_it_spec.rb
|
122
|
+
- spec/rspec/expect_it/expectation_targets/expect_its_spec.rb
|
116
123
|
- spec/rspec/expect_it/helpers_spec.rb
|
117
124
|
- spec/spec_helper.rb
|