Update
This commit is contained in:
parent
51b0212eb1
commit
eddc632c29
47
rspec.md
47
rspec.md
|
@ -22,18 +22,15 @@ category: Ruby
|
|||
end
|
||||
end
|
||||
|
||||
### A test
|
||||
## A tests
|
||||
|
||||
```rb
|
||||
describe "A User (in general)" do
|
||||
include UserSpecHelper
|
||||
|
||||
before(:each) do
|
||||
@user = User.new
|
||||
end
|
||||
subject { Person.new }
|
||||
|
||||
subject {
|
||||
Person.new
|
||||
}
|
||||
let(:admin) { Person.new(role: :admin) }
|
||||
|
||||
context "setter methods" do
|
||||
it "should do this" do
|
||||
|
@ -43,8 +40,34 @@ category: Ruby
|
|||
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
|
||||
target.should eq 1
|
||||
|
@ -150,7 +173,6 @@ expect(die).to receive(:roll)
|
|||
.with(kind_of(Numeric))
|
||||
.with(<matcher>)
|
||||
|
||||
|
||||
.once
|
||||
.twice
|
||||
.exactly(n).times
|
||||
|
@ -163,10 +185,3 @@ expect(die).to receive(:roll)
|
|||
```
|
||||
|
||||
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