rspec-expect_it 1.0.2 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fa17ef9a6126ec059a950e5bea9374d6444a076
4
- data.tar.gz: 1761665e209ee2cb01bd7396781f0f3e830c786f
3
+ metadata.gz: 51ec398861a336d50321dab80df562099db054be
4
+ data.tar.gz: 4b84547c0eb3cf94a52264a854f7b60dff291b0c
5
5
  SHA512:
6
- metadata.gz: 0f00ca7c27bba04a0b7060e6dcf202436765442c91875516624e444f22c2d770e23a28f3622ae34dfa266e0364b510299158e3b2df7186c3e36c635ed08c65b8
7
- data.tar.gz: 8a11d4d66d24a4d014e4c2e2be96b85ddd3c82b50e04b8d8315debea0facc7b32b94e2851429d6898f162bcf664c4256cbe76602683635c74900a49f0387e078
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(@value) }
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
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module ExpectIt
3
- VERSION = "1.0.2"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  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 }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-expect_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Drake-Brockman