Improving specs with RSpec 3

17
Improving specs with RSpec 3 A talk for @globaldev by @jamesjoshuahill

Transcript of Improving specs with RSpec 3

Improving specs!with RSpec 3

A talk for @globaldev!by @jamesjoshuahill

When I break behaviour!I want specs to fail

When I refactor!I want specs to pass

RSpec 3

Verifying doubles

config.mock_with :rspec do |mocks|

# Protect against typos

mocks.verify_doubled_constant_names = true

# Will be a default in RSpec 4

mocks.verify_partial_doubles = true

end

Composable matchers

expect(answer).to be_within(0.1).of(42)

!

expect(message).to start_with(“hi”) .and end_with(“bye”)

expect(data).to match(

:answer => a_value_within(0.1).of(42),

:message => a_string_starting_with(“hi”) .and ending_with(“bye”)

)

Test spies

Transpecyujinakayama.me/transpec

$ transpec --keep its

subject { app }

# Bundle rspec-its gem to use old syntax

its(:data) { should eq “hello” }

!

!

!

!

!

!

# Or convert examples manually

it “returns the data” do expect(subject.data).to eq “hello” end

Any questions?