rspec-expect_it 1.0.2 → 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/README.md +23 -1
- data/lib/rspec/expect_it/helpers.rb +23 -0
- data/lib/rspec/expect_it/version.rb +1 -1
- data/spec/rspec/expect_it/helpers_spec.rb +49 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51ec398861a336d50321dab80df562099db054be
|
4
|
+
data.tar.gz: 4b84547c0eb3cf94a52264a854f7b60dff291b0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 615686cff1d8f349b6e15dca8bc139a8582ed7a0849eb576a146bc2bf580f63d16e84efbea8450206aed20513333346390540044572788114bc6cd101025a3dc
|
7
|
+
data.tar.gz: c0a801aafc942040c0b7aa979e85cb1adebb84e837af4199f7fcd9a7f612c53695df351b76c30c3ce55a264484bcf16b59f27a8d084090b16749823b0f8037f6
|
data/README.md
CHANGED
@@ -47,7 +47,7 @@ If you want eager evaluation of the subject, use `expect_it!`.
|
|
47
47
|
```ruby
|
48
48
|
subject { @value += 1 }
|
49
49
|
|
50
|
-
specify { expect_it!.to eq
|
50
|
+
specify { expect_it!.to eq @value }
|
51
51
|
```
|
52
52
|
|
53
53
|
### expect_it{}
|
@@ -60,6 +60,28 @@ subject { @value += 1 }
|
|
60
60
|
specify { expect_it{}.to change{@value}.by(1) }
|
61
61
|
```
|
62
62
|
|
63
|
+
### expect_its
|
64
|
+
|
65
|
+
Calling `expect_its(:method)` is equivalent to `expect(subject.method)`.
|
66
|
+
There is no `_safe` version of this helper.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
subject { "foobar" }
|
70
|
+
|
71
|
+
specify { expect_its(:length).to eq 6 }
|
72
|
+
```
|
73
|
+
|
74
|
+
### expect_its!
|
75
|
+
|
76
|
+
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
|
+
```ruby
|
80
|
+
subject { @value += 1 }
|
81
|
+
|
82
|
+
specify { expect_its!(:to_s).to eq @value.to_s }
|
83
|
+
```
|
84
|
+
|
63
85
|
### expect_it_safe
|
64
86
|
|
65
87
|
The `expect_it_safe` helper is the same as `expect_it`, except that it will
|
@@ -13,6 +13,14 @@ module RSpec
|
|
13
13
|
expect(subject)
|
14
14
|
end
|
15
15
|
|
16
|
+
def expect_its(method)
|
17
|
+
ExpectItsExpectationTarget.new(self, method)
|
18
|
+
end
|
19
|
+
|
20
|
+
def expect_its!(method)
|
21
|
+
expect(subject.send(method))
|
22
|
+
end
|
23
|
+
|
16
24
|
def expect_it_safe
|
17
25
|
if block_given?
|
18
26
|
safe_lambda = lambda do
|
@@ -72,6 +80,21 @@ module RSpec
|
|
72
80
|
end
|
73
81
|
end
|
74
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)
|
96
|
+
end
|
97
|
+
end
|
75
98
|
end
|
76
99
|
end
|
77
100
|
end
|
@@ -19,7 +19,7 @@ describe RSpec::ExpectIt::Helpers do
|
|
19
19
|
describe "unsaftey" do
|
20
20
|
subject { raise Exception }
|
21
21
|
|
22
|
-
specify { expect{expect_it.to be nil}.to raise_error(Exception) }
|
22
|
+
specify { expect{ expect_it.to be nil }.to raise_error(Exception) }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -62,6 +62,54 @@ describe RSpec::ExpectIt::Helpers do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
describe "expect_its" do
|
66
|
+
describe "equalivalence" do
|
67
|
+
let(:result) { Object.new }
|
68
|
+
|
69
|
+
subject { double("subject").tap {|s| s.stub(:method) { result } } }
|
70
|
+
|
71
|
+
specify { expect_its(:method).to eq subject.method }
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "lazy evaluation" do
|
75
|
+
before { @value = 0 }
|
76
|
+
|
77
|
+
subject { double("subject").tap {|s| s.stub(:method) { @value = 1 } } }
|
78
|
+
|
79
|
+
specify { expect_its(:method).to eq (@value + 1) }
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "unsaftey" do
|
83
|
+
subject { double("subject").tap {|s| s.stub(:method) { raise Exception } } }
|
84
|
+
|
85
|
+
specify { expect{ expect_its(:method).to eq nil }.to raise_error(Exception) }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "expect_its!" do
|
90
|
+
describe "equalivalence" do
|
91
|
+
let(:result) { Object.new }
|
92
|
+
|
93
|
+
subject { double("subject").tap {|s| s.stub(:method) { result } } }
|
94
|
+
|
95
|
+
specify { expect_its!(:method).to eq subject.method }
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "unlazy evaluation" do
|
99
|
+
before { @value = 0 }
|
100
|
+
|
101
|
+
subject { double("subject").tap {|s| s.stub(:method) { @value = 1 } } }
|
102
|
+
|
103
|
+
specify { expect_its!(:method).to eq @value }
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "unsaftey" do
|
107
|
+
subject { double("subject").tap {|s| s.stub(:method) { raise Exception } } }
|
108
|
+
|
109
|
+
specify { expect{ expect_its!(:method).to eq nil }.to raise_error(Exception) }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
65
113
|
describe "expect_it_safe" do
|
66
114
|
describe "equalivalence" do
|
67
115
|
subject { Object.new }
|