Top Banner
Improving specs with RSpec 3 A talk for @globaldev by @jamesjoshuahill
17
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Improving specs with RSpec 3

Improving specs!with RSpec 3

A talk for @globaldev!by @jamesjoshuahill

Page 2: Improving specs with RSpec 3
Page 3: Improving specs with RSpec 3

When I break behaviour!I want specs to fail

Page 4: Improving specs with RSpec 3

When I refactor!I want specs to pass

Page 5: Improving specs with RSpec 3
Page 6: Improving specs with RSpec 3

RSpec 3

Page 7: Improving specs with RSpec 3

Verifying doubles

Page 8: Improving specs with RSpec 3

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

Page 9: Improving specs with RSpec 3

Composable matchers

Page 10: Improving specs with RSpec 3

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

!

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

Page 11: Improving specs with RSpec 3

expect(data).to match(

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

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

)

Page 12: Improving specs with RSpec 3

Test spies

Page 13: Improving specs with RSpec 3
Page 14: Improving specs with RSpec 3

Transpecyujinakayama.me/transpec

Page 15: Improving specs with RSpec 3

$ transpec --keep its

Page 16: Improving specs with RSpec 3

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

Page 17: Improving specs with RSpec 3

Any questions?