-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrspec.txt
120 lines (94 loc) · 2.64 KB
/
rspec.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
it and specify are alias of example
context is an alias for describe. Usually you mix context and describe like this
describe User do
context "with no roles assigned" do
it "should not be allowed to view protected content" do
--format nested
--format diff
--format specfoc
--format html:/report.html
PENDING
==============
describe "onion rings" do
it "should not be mixed with french fries" do
pending "cleaning out the fryer"
fryer_with(:onion_rings).should_not include(:french_fry)
end
end
In the following case rspec will actually run the test inside pending. If the test
passes then rspec will tell you that an unnecessary pending
describe "an empty array" do
it "should be empty" do
pending("bug report 18976") do
[].should be_empty
end
end
end
SHARE methods in rspec
Spec::Runner.configure do |config|
config.include(UserExampleHelpers)
end
shared_examples_for "Any Pizza" do
it "should taste really good" do
@pizza.should taste_really_good
end
it "should be available by the slice" do
@pizza.should be_available_by_the_slice
end
end
describe "New York style thin crust pizza" do
it_should_behave_like "Any Pizza"
before(:each) do
@pizza = Pizza.new(:region => 'New York', :style => 'thin crust')
end
it "should have a really great sauce" do
@pizza.should have_a_really_great_sauce
end
end
describe "Chicago style stuffed pizza" do
it_should_behave_like "Any Pizza"
before(:each) do
@pizza = Pizza.new(:region => 'Chicago', :style => 'stuffed')
end
it "should have a ton of cheese" do
@pizza.should have_a_ton_of_cheese
end
end
share_as :AnyPizza do
...
end
describe "New York style thin crust pizza" do
include AnyPizza ...
end
describe "Chicago style stuffed pizza" do
include AnyPizza ...
end
user.should be_in_role("admin")
user.in_role?("admin")
request_parameters.should have_key(:id)
request_parameters.has_key?(:id)
implicit subject
describe RSpecUser do
it { should be_happy }
end
describe Person do
subject { Person.new(:birthdate => 19.years.ago) }
specify { subject.should be_eligible_to_vote }
end
describe Person do
subject { Person.new(:birthdate => 19.years.ago) }
it { should be_eligible_to_vote }
end
describe User do
context "create a user" do
subject { User.create(:email => 'sec...@example.com') }
# in the below case either one can use specify or its. its does not work out in all
# conditions but in some conditions it read better
specify { subject.id.should_not be_nil}
its(:id) { should_not be_nil}
end
end
= use as_*
def null_object(*args)
double(*args).as_null_object
end