rspec_candy 0.1.1 → 0.1.2
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.
data/README.md
CHANGED
@@ -1,4 +1,132 @@
|
|
1
|
-
|
1
|
+
#rspec_candy
|
2
|
+
|
3
|
+
|
4
|
+
A collection of nifty helpers for your rspec suite.
|
5
|
+
|
6
|
+
Will work for RSpec1 and Rails 2, or RSpec2 and Rails 3, or no Rails at all..
|
7
|
+
|
8
|
+
|
9
|
+
##Usage
|
10
|
+
|
11
|
+
Add `rspec_candy` to your Gemfile.
|
12
|
+
Add `require 'rspec_candy/helpers'` to your spec_helper.rb, after the rspec requires.
|
13
|
+
|
14
|
+
|
15
|
+
##Helpers provided
|
16
|
+
|
17
|
+
|
18
|
+
### Extensions to **Object**
|
19
|
+
|
20
|
+
**should_receive_and_execute**
|
21
|
+
|
22
|
+
Like "should_receive", but also executes the method.
|
23
|
+
|
24
|
+
|
25
|
+
**should_receive_and_return**
|
26
|
+
|
27
|
+
Expects multiple returns at once:
|
28
|
+
|
29
|
+
dog.should_receive_and_return(:bark => "Woof", :fetch => "stick")
|
30
|
+
|
31
|
+
|
32
|
+
**should_receive_chain**
|
33
|
+
|
34
|
+
Expect a chain of method calls:
|
35
|
+
|
36
|
+
dog.should_receive_chain(:bark, :upcase).and_return("WOOF")
|
37
|
+
|
38
|
+
|
39
|
+
You can also expect arguments, like:
|
40
|
+
|
41
|
+
dog.should_receive_chain([:bark, 'loudly'], :upcase).and_return("WOOF!!!")
|
42
|
+
|
43
|
+
|
44
|
+
**stub_existing**
|
45
|
+
|
46
|
+
Like stub, put complains if the method did not exist in the first place.
|
47
|
+
|
48
|
+
|
49
|
+
### Extensions to **Class**
|
50
|
+
|
51
|
+
**disposable_copy**
|
52
|
+
|
53
|
+
Like dup for classes. This will temporarily add a method to a class:
|
54
|
+
|
55
|
+
copy = Model.disposable_copy.class_eval do
|
56
|
+
def foo; end
|
57
|
+
end
|
58
|
+
|
59
|
+
object = copy.new
|
60
|
+
|
61
|
+
|
62
|
+
**new_with_stubs**
|
63
|
+
|
64
|
+
Instantiates and stubs in one call:
|
65
|
+
|
66
|
+
Model.new_with_stubs(:to_param => '1')
|
67
|
+
|
68
|
+
**stub_any_instance**
|
69
|
+
|
70
|
+
Backport for `any_instance.stub` to RSpec1.
|
71
|
+
|
72
|
+
|
73
|
+
### Extensions to **example groups**
|
74
|
+
|
75
|
+
**it_should_act_like**
|
76
|
+
|
77
|
+
Extension to 'it_should_behave_like`, not necessary for RSpec2.
|
78
|
+
|
79
|
+
Allows parametrizing shared examples, exposes parameters as lets:
|
80
|
+
|
81
|
+
shared_examples_for "an animal" do
|
82
|
+
it 'should make noises' do
|
83
|
+
subject.say.should == expected_noise
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe Dog do
|
88
|
+
it_should_act_like 'an animal', :expected_noise => 'Woof!'
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
Blocks are passed as a let named "block".
|
93
|
+
|
94
|
+
|
95
|
+
**it_should_run_callbacks**
|
96
|
+
|
97
|
+
Only on Rails.
|
98
|
+
|
99
|
+
Check if callbacks are run. Note the name of the describe block is significant:
|
100
|
+
|
101
|
+
describe Model, '#after_save' do
|
102
|
+
it_should_run_callbacks :notify_this, :notify_that
|
103
|
+
end
|
104
|
+
|
105
|
+
If you use the state_machine gem, you can also spec callbacks for state_machine transitions:
|
106
|
+
|
107
|
+
|
108
|
+
describe Model, '#my_event from :my_state1 to :my_state" do
|
109
|
+
it_should_run_callbacks :notify_this, :notify_that
|
110
|
+
end
|
111
|
+
|
112
|
+
**it_should_run_callbacks_in_order**
|
113
|
+
|
114
|
+
Like `it_should_run_callbacks`, but also checks the correct order.
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
### Extensions to **ActiveRecord::Base**
|
120
|
+
|
121
|
+
**create_without_callbacks**
|
122
|
+
|
123
|
+
Only on Rails.
|
124
|
+
|
125
|
+
Creates a record without validations or callbacks (like a stub in the database). Can be significantly faster than a factory.
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
##Changes from previous versions:
|
2
130
|
|
3
131
|
- `new_and_store` has been renamed `create_without_callbacks`
|
4
132
|
- `keep_invalid!` has been renamed to `prevent_storage`
|
data/lib/rspec_candy/version.rb
CHANGED
data/spec/rspec1/spec_helper.rb
CHANGED
data/spec/rspec2/spec_helper.rb
CHANGED
@@ -38,6 +38,14 @@ describe RSpecCandy::Helpers::DisposableCopy do
|
|
38
38
|
Model.new.should_not respond_to(:foo)
|
39
39
|
end
|
40
40
|
|
41
|
+
it 'should evaluate the block after the copy has been renamed to the original class name' do
|
42
|
+
spy = mock('spy')
|
43
|
+
spy.should_receive(:observe_name).with('Model')
|
44
|
+
Model.disposable_copy do
|
45
|
+
spy.observe_name(name)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
41
49
|
end
|
42
50
|
|
43
51
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_candy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Henning Koch
|
@@ -16,7 +16,8 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-05
|
19
|
+
date: 2012-07-05 00:00:00 +02:00
|
20
|
+
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
23
|
name: rspec
|
@@ -122,6 +123,7 @@ files:
|
|
122
123
|
- spec/shared/support/matchers/pass_as_example.rb
|
123
124
|
- template/spec_candy.rails2.rb
|
124
125
|
- template/spec_candy.rails3.rb
|
126
|
+
has_rdoc: true
|
125
127
|
homepage: https://github.com/makandra/rspec_candy
|
126
128
|
licenses: []
|
127
129
|
|
@@ -151,10 +153,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
153
|
requirements: []
|
152
154
|
|
153
155
|
rubyforge_project:
|
154
|
-
rubygems_version: 1.
|
156
|
+
rubygems_version: 1.3.9.4
|
155
157
|
signing_key:
|
156
158
|
specification_version: 3
|
157
159
|
summary: RSpec helpers and matchers we use in our daily work at makandra.
|
158
160
|
test_files: []
|
159
161
|
|
160
|
-
has_rdoc:
|