-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit_test_spec.rb
67 lines (57 loc) · 1.3 KB
/
unit_test_spec.rb
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
describe SomeClass do
context "when defining a subject" do
# GOOD
# it's okay to define a `subject` here:
subject { "foo" }
it { should eq "foo" }
end
context "when using an explicit subject" do
subject { "foo" }
it "should equal foo" do
# BAD
# although it's valid RSpec code and this test passes,
# it's not okay to use `subject` here:
expect(subject).to eq "foo"
end
end
describe ".some_class_method" do
it "does something" do
# ...
end
end
describe "#some_instance_method" do
it "does something" do
expect(something).to eq "something"
end
end
describe "#another_instance_method" do
context "when in one case" do
it "does something" do
# ...
end
end
context "when in other case" do
it "does something else" do
# ...
end
end
end
# Good
# One expectation per `it`
describe "#update" do
it "sets the phone number" do
expect(phone_number).to eq "+123456789"
end
it "sets the postal_code" do
expect(postal_code).to eq "000000"
end
end
# Bad
# Multiple expectations per `it`
describe "#update" do
it "sets attributes" do
expect(phone_number).to eq "+123456789"
expect(postal_code).to eq "000000"
end
end
end