w2d3 Flashcards

1
Q

What’s the difference between RSpec’s ‘eq’ and ‘be’ expectation matchers?

A

‘eq’ uses == to test equality

‘be’ compares object_id’s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In RSpect, wat are the #eq and #be methods called?

A

expectation matchers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you set up a context to run in RSpec?

A

with a ‘before’ block

Specifically, a before(:each) block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why do we avoid using a before(:all) block?

A

The test context is shared and can make tests brittle in that they become dependent on each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you write out a bunch of descriptions for specs without writing the bodies?

A

leave out the block on the ‘it’ blocks:

it ‘does something awesome’
it ‘does another great thing’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does the RSpec::describe method work? How does it do this on the backend?

A

It takes a classname as an argument and stores a reference to it within the context’s metadata hash.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you do a comparison in a spec?

A

expect(actual).to be < expected

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you do a delta comparison in a spec?

A

expect(actual).to be_within(delta).of(expected)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you test an exception in a spec?

A

expect { … }.to raise_error(ErrorClass)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What’s the relationship between subjects and lets?

A

a subject is the main subject of the test. There can be only one (unnamed) subject.

a let is a helper object. There can be many let’s in a test.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do we set up a mock object?

A

double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Difference between unit tests and integration tests?

A

unit tests test objects in vitro

integration tests test groups of objects in vivo

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How would you set up a double for a User object that has a name of “Jim” and an address of “123 main st” ?

A

person = double(“person”, :name => ‘Jim’, :address => ‘123 main st’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How would you ensure that a particular method within a double is called, with a particular result? How would you write the test?

A

person = double(:name => ‘Jim’)

Renamer.do_rename(person)

expect(person).to receive(:name).with(‘Jim’)

expect(person).to receive(:name).and_return(‘Jim’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Where do you declare the subject?

A

Outside of your it block.

The same subject will be used for all it blocks within a describe block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What’s a good rule when figuring out how deeply to nest a style rule?

A

Be only as specific as necessary.

17
Q

How does “Be only as specific as necessary” apply to style sheets?

A

Don’t specify everything on a per-id level. This leads to a non-DRY environment.