Update
This commit is contained in:
parent
51b0212eb1
commit
eddc632c29
63
rspec.md
63
rspec.md
|
@ -22,29 +22,52 @@ category: Ruby
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
### A test
|
## A tests
|
||||||
|
|
||||||
describe "A User (in general)" do
|
```rb
|
||||||
include UserSpecHelper
|
describe "A User (in general)" do
|
||||||
|
include UserSpecHelper
|
||||||
|
|
||||||
before(:each) do
|
subject { Person.new }
|
||||||
@user = User.new
|
|
||||||
end
|
|
||||||
|
|
||||||
subject {
|
let(:admin) { Person.new(role: :admin) }
|
||||||
Person.new
|
|
||||||
}
|
|
||||||
|
|
||||||
context "setter methods" do
|
context "setter methods" do
|
||||||
it "should do this" do
|
it "should do this" do
|
||||||
pending "some other thing"
|
pending "some other thing"
|
||||||
|
|
||||||
expect(subject.name).to eq 'x'
|
expect(subject.name).to eq 'x'
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
### Expectations
|
### Before/after
|
||||||
|
|
||||||
|
```rb
|
||||||
|
before :each do
|
||||||
|
# before all tests
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
# before this suite
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
# after this suite
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
### Subjects
|
||||||
|
|
||||||
|
```rb
|
||||||
|
subject { CheckingAccount.new }
|
||||||
|
it { is_expected.to be_empty }
|
||||||
|
|
||||||
|
# also names: subject(:account) { ... }
|
||||||
|
```
|
||||||
|
|
||||||
|
## Expectations
|
||||||
|
|
||||||
```rb
|
```rb
|
||||||
target.should eq 1
|
target.should eq 1
|
||||||
|
@ -150,7 +173,6 @@ expect(die).to receive(:roll)
|
||||||
.with(kind_of(Numeric))
|
.with(kind_of(Numeric))
|
||||||
.with(<matcher>)
|
.with(<matcher>)
|
||||||
|
|
||||||
|
|
||||||
.once
|
.once
|
||||||
.twice
|
.twice
|
||||||
.exactly(n).times
|
.exactly(n).times
|
||||||
|
@ -163,10 +185,3 @@ expect(die).to receive(:roll)
|
||||||
```
|
```
|
||||||
|
|
||||||
https://relishapp.com/rspec/rspec-mocks/docs
|
https://relishapp.com/rspec/rspec-mocks/docs
|
||||||
|
|
||||||
## Subjects
|
|
||||||
|
|
||||||
describe CheckingAccount, "with a non-zero balance" do
|
|
||||||
subject(:account) { CheckingAccount.new }
|
|
||||||
it { is_expected.not_to be_overdrawn }
|
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in New Issue