Ruby on Rails on Minitest.key

Preview:

Citation preview

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Ruby on Rails on Minitest

1

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Setting ExpectationsIntroductory Talk.

Very Little Code.

Not going to teach testing or TDD.

What & why, not how.

218 Slides, 5.45 SPM.2

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

WTF is minitest?

3

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

What is Minitest?Replacement for ruby 1.8’s test/unit.

Originally 90 lines of code, only test/unit basics.

Available as a gem, and ships with ruby 1.9.1 & up.

Meant to be small, clean, and very fast.

Now ~1600 loc, unit, spec, benchmarks, mock/stub, plugins, etc.4

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

6 Parts of Minitestrunner The heart of the machine

minitest/unit TDD API

minitest/spec BDD API

minitest/mock Simple mocking API

minitest/pride IO pipelining example

minitest/bench Abstract benchmark API 5

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

2 Parts of Minitestrunner The heart of the machine

minitest/unit TDD API

minitest/spec BDD API

minitest/mock Simple mocking API

minitest/pride IO pipelining example

minitest/bench Abstract benchmark API 6

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

minitest/test

7

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Test Cases are

Classes8

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Tests are

Methods9

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

require "minitest/autorun"

class TestThingy < Minitest::Test def test_do_the_thing assert_equal 42, Thingy.do_the_thing end end

Test Example

10

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

require "minitest/autorun"

class TestThingy < Minitest::Test def test_do_the_thing assert_equal 42, Thingy.do_the_thing end end

Test ExampleSimple Subclass

10

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

require "minitest/autorun"

class TestThingy < Minitest::Test def test_do_the_thing assert_equal 42, Thingy.do_the_thing end end

Test ExampleSimple Subclass

Simple Method

10

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

require "minitest/autorun"

class TestThingy < Minitest::Test def test_do_the_thing assert_equal 42, Thingy.do_the_thing end end

Test Example

Magic Free!

Simple Subclass

Simple Method

10

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Positive Assertionsassert

assert_empty

assert_equal

assert_in_delta

assert_in_epsilon+

assert_includes+

assert_instance_of

assert_kind_of

assert_match

assert_nil

assert_operator

assert_output*+

assert_predicate+

assert_raises*

assert_respond_to

assert_same

assert_send*

assert_silent*+

assert_throws*

11

*no negative equiv+not in testunit

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Negative Assertionsrefute+

refute_empty+

refute_equal

refute_in_delta+

refute_in_epsilon+

refute_includes+

refute_instance_of+

refute_kind_of+

refute_match

refute_nil

refute_operator+

refute_output

refute_predicate+

refute_raises

refute_respond_to+

refute_same

refute_send

refute_silent

refute_throws

12

+not in testunit

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

assert ! obj refute obj

assert collection.include? obj assert_includes obj, collection

out, err = capture_io do do_something end assert_equal "output", out assert_equal "", err

assert_output "output", "" do do_something end

Why all these extra assertions? They're more expressive!

13

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

assert_equal diffs: 1) Failure: test_failing_simple(TestSimple) [example.rb:8]: Expected: 42 Actual: 24

2) Failure: test_failing_complex(TestComplex) [example.rb:23]: --- expected +++ actual @@ -22,7 +22,7 @@ "line 22", "line 23", "line 24", - "line 25", + "something unexpected", "line 26", "line 27", "line 28",

14

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

But...15

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Where is refute_raises?

16

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Same place as refute_silent.

17

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

refute_silentThis block of code must print something.

What it is, I don't care.

How is this assertion of value to anyone?

Assert for the specific output you need.18

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

refute_silentThis block of code must print something.

What it is, I don't care.

How is this assertion of value to anyone?

Assert for the specific output you need.19

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

refute_raisesThis block of code must do something.

What it is, I don't care.

How is this assertion of value to anyone?

Assert for the specific result you need.20

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

“It's Useful”No it isn't.

Implies side effects and/or return values have been checked.

Or aren't important (always false—otherwise, why write the code?).

Falsely bumps code coverage metrics.

False sense of security.

21

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

“It's More Expressive”No it isn't.

Writing the test was the act of expression.

It is an explicit contract in any test framework that unhandled exceptions are an error.

The test's mere existence explicitly states: "there are no unhandled exceptions via these pathways".

22

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

I've been having this argument for years

23

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Some people will never be convinced

24

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Stand Back25

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

def check_everything assert_something_output do assert_nothing_raised do assert_some_side_effect do assert_some_response do yield end end end end end

26

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

def check_everything assert_something_output do assert_nothing_raised do assert_some_side_effect do assert_some_response do yield end end end end end

26

©2015 Ryan DavisAll Rights Reserved

ISO 9001Enterprise Certified™

Available for $$$$

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider27

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

minitest/spec

28

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Testing DSL29

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Test Cases are

`describe` blocks30

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Tests are

`it` blocks31

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Spec Examplerequire "minitest/autorun"

describe Thingy do it "must do the thing" do _(Thingy.do_the_thing).must_equal 42 end end

32

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

But33

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

In Reality34

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

`describe` blocks are

Classes35

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

`it` blocks are

Methods36

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Spec Examplerequire "minitest/autorun"

describe Thingy do it "must do the thing" do _(Thingy.do_the_thing).must_equal 42 end end

37

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

require "minitest/autorun"

class TestThingy < Minitest::Test def test_0001_must_do_the_thing _(Thingy.do_the_thing).must_equal 42 end end

Specs Transform:

38

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

require "minitest/autorun"

class TestThingy < Minitest::Test def test_0001_must_do_the_thing _(Thingy.do_the_thing).must_equal 42 end end

Simple Subclass

Specs Transform:

38

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

require "minitest/autorun"

class TestThingy < Minitest::Test def test_0001_must_do_the_thing _(Thingy.do_the_thing).must_equal 42 end end

Simple Subclass

Simple Method

Specs Transform:

38

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

require "minitest/autorun"

class TestThingy < Minitest::Test def test_0001_must_do_the_thing _(Thingy.do_the_thing).must_equal 42 end end

Magic Free!

Simple Subclass

Simple Method

Specs Transform:

38

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Positive Expectationsmust_be

must_be_close_to

must_be_empty

must_be_instance_of

must_be_kind_of

must_be_nil

must_be_same_as

must_be_silent*

must_be_within_delta

must_be_within_epsilon

must_equal

must_include

must_match

must_output*

must_raise*

must_respond_to

must_send*

must_throw*

39

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Negative Expectationswont_be

wont_be_close_to

wont_be_empty

wont_be_instance_of

wont_be_kind_of

wont_be_nil

wont_be_same_as

wont_be_silent

wont_be_within_delta

wont_be_within_epsilon

wont_equal

wont_include

wont_match

wont_output

wont_raise

wont_respond_to

wont_send

wont_throw

40

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

All for Freemust_equal is assert_equal

wont_equal is refute_equal

etc.

41

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Advanced Testing

42

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Randomization Baked In

43

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Preventing Test Order Dependencies

44

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

parallelize_me!45

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Turn up the test levels

46

Randomize Test Order

Require Proof of Success?

Fast

Test

Runn

er

Forced Parallelization

01

2

3

45

6 78

9

1011

Disallow meaningless assertions

???

test + spec

Benchmark TestsUse gem, not stdlib

Writ

e cu

stom

ass

ertio

ns

Refac

tor to

reus

able

testca

ses

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Design Rationale

47

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

It's Just Ruby™48

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

require "minitest/autorun"

class TestThingy < Minitest::Test def test_do_the_thing assert_equal 42, Thingy.do_the_thing end end

Look! Ruby!

49

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Less is More50

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

def assert_in_delta e, a, d = 0.001, m = nil n = (e - a).abs msg = message(m) { "... failure message ..." } assert delta >= n, msg end

assert_in_delta

51

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

def assert_in_delta e, a, d = 0.001, m = nil n = (e - a).abs msg = message(m) { "... failure message ..." } assert delta >= n, msg end

assert_in_delta

message takes a block to defer

calculation until an assertion fails

51

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

def assert_in_delta e, a, d = 0.001, m = nil n = (e - a).abs msg = message(m) { "... failure message ..." } assert delta >= n, msg end

assert_in_delta

simple assertion is all that is needed

message takes a block to defer

calculation until an assertion fails

51

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

def assert_in_delta e, a, d = 0.001, m = nil n = (e - a).abs msg = message(m) { "... failure message ..." } assert delta >= n, msg end

assert_in_delta

Only 2 other methods need to be understood:assert (9) & message (6)

simple assertion is all that is needed

message takes a block to defer

calculation until an assertion fails

51

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Indirection is the Enemy

52

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Just 2 Hopsmodule Minitest::Expectation def must_equal(*args) ctx.assert_equal(*args) end end

module Minitest::Assertions def assert_equal exp, act, msg = nil msg = message(msg, E) { diff exp, act } assert exp == act, msg end end

53

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

No Magic Allowed

54

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Thriving Plugin Ecosystemminitest-chef-handler

minitest-reporters

minitest-rails

guard-minitest

minitest-spec-rails

minitest-capybara

spork-minitest

minitest-metadata

minitest-rails-capybara

minitest-matchers

capybara_minitest_spec

minitest-colorize

minitest-rg

minitest-ci

55

(& many more)

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Rails & Minitest

56

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

The Official Rails Stack™

uses Minitest57

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Each Release58

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Peels back the testing

onion59

https://www.flickr.com/photos/darwinbell/303874154

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Encouraging better testing practices

60

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Peeling onions make

you cry61

https://www.flickr.com/photos/marleahjoy/13153221935

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Right?62

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

(Hopefully) Not Here

63

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Rails 4.0 minitest 4.x

64

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Impact? Zero

65

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Rails 4.1 minitest 5.x

66

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Impact? Zero

67

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Rails 4.2 random order

68

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Some Impact?69

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Good Thing™!70

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Future Rails Should track minitest.

71

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

As a Rails Dev72

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

What does all of this

mean?73

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Hopefully...74

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Nothing75

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

ActiveSupport ::TestCase

76

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest::Test

ActiveSupport::TestCase

MyThingyTest

Basic Architecture

77

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Per-test database transactions

78

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Fixtures# In fixtures/categories.yml about:   name: About   # In fixtures/articles.yml one:   title: Welcome to Rails!   body: Hello world!   category: about

79

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Declarative Formssetup do # ... end

teardown do # ... end

test “test name” do # ... end

80

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Extra Assertionsassert_difference

assert_valid_keys

assert_deprecated

assert_nothing_raised81

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Wait? What?!?82

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Don't Worry! def assert_nothing_raised(*args) yield end

83

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Don't Worry! def assert_nothing_raised(*args) yield end

83

ActualImplementation

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Unit Testingrequire 'test_helper'   class ArticleTest < ActiveSupport::TestCase test "should not save article without title" do article = Article.new refute article.save end end

84

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

ActionController ::TestCase

85

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Basic Architecture

86

Minitest::Test

ActiveSupport::TestCase

MyControllerTest

ActionController::TestCase

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Actionsget

post

delete

etc87

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Staterequest

response

session

flash88

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Assertionsassert_response

assert_redirected_to

assert_template

89

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Functional Testingclass ArticlesControllerTest < ActionController::TestCase test "should get index" do get :index assert_response :success assert_not_nil assigns(:articles) end end

90

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

ActiveDispatch ::IntegrationTest

91

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest::Test

ActiveSupport::TestCase

MyIntegrationTest

ActionDispatch::IntegrationTest

Architecture

92

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Assertions

Tons93

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Integration Testingclass UserFlowsTest < ActionDispatch::IntegrationTest   test "login and browse site" do     https!     get "/login"     assert_response :success   david = users :david     post_via_redirect "/login", username: david.username, password: david.password     assert_equal '/welcome', path     assert_equal 'Welcome david!', flash[:notice]       https! false     get "/articles/all"     assert_response :success     assert assigns :articles   end end

94

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

http://guides.rubyonrails.org/

testing.html95

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Very Simple96

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Very Powerful97

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Leverages Minitest

98

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Test Randomization

99

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Parallelization100

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Enforce Better Testing

101

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Troubleshooting

102

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

I want to use minitest, but I

prefer spec-style…103

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Simple104

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

minitest-rails105

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

minitest-spec-rails

106

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Lets you do this:describe User do let(:user) { User.create! ... }

it "does the thing to the stuff" do user.username.must_match(/.../) end end

107

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

I upgraded to rails 4.2 and now I have

failures108

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

AKA: you broke all my

shit109

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Not as Simple110

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Test-Order Dependency Bug

111

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

ran: a, b, c = pass ran: b, a, c = fail

112

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Easy!113

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

“But, I have hundreds of tests!”

114

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Not so Easy115

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

minitest-bisect116

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Helps you isolate and debug

random test failures117

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider118

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider118

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

I'm used to RSpec + factory-girl + this + that

+ kitchen sink + everything

119

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

A lot of stuff Just Works™

120

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Look for plugins in readme / gems

121

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

My Suggestion?122

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Less Complicated Testing

123

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Try It124

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

You Might Like It

125

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Change Takes Time

126

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Why use minitest?

127

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

“Why Test?” aka

“It slows me down”128

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Not Going to Bother

129

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Lost Cause130

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

I'd rather help other people

131

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

“Everyone Uses RSpec”

132

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Obviously Not133

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

The Official Rails Stack™

uses Minitest134

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

DHH uses minitest

135

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

tenderlove uses minitest

136

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Jeff Casimir & cohort teach minitest at

Turing School137

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

nokogiri, haml, god, newrelic_rpm, sqlite3

138

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

etc139

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Functional Differences with

RSpec140

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Unique Features of RSpecTest metadata & metadata filtering.

Fancier expectations, negation, etc.

Shared contexts & example groups.

Implicit subject, described_class, etc.

before(:all) & around(:each).

Fancier mocking.

Fancier reporting.141

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Unique Features of RSpecTest metadata & metadata filtering.

Fancier expectations, negation, etc.

Shared contexts & example groups.

Implicit subject, described_class, etc.

before(:all) & around(:each).

Fancier mocking.

Fancier reporting.141

Basically, it's Fancier

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Unique Features of MinitestUnit & Spec Style Testing.

Über-Duper fast and lightweight.

Easy to understand whole library.

minitest/pride.

Benchmark tests.

First to randomize

parallelize_me! & minitest/hell

Clean & easy plugin system.

Smallest mock/stub framework.

142

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Unique Features of MinitestUnit & Spec Style Testing.

Über-Duper fast and lightweight.

Easy to understand whole library.

minitest/pride.

Benchmark tests.

First to randomize

parallelize_me! & minitest/hell

Clean & easy plugin system.

Smallest mock/stub framework.

142

Simple, Pragmatic

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Unique Features of MinitestUnit & Spec Style Testing.

Über-Duper fast and lightweight.

Easy to understand whole library.

minitest/pride.

Benchmark tests.

First to randomize

parallelize_me! & minitest/hell

Clean & easy plugin system.

Smallest mock/stub framework.

142

Simple, Pragmaticand a bit Snarky

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Cognitive differences with

RSpec143

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Myron Marston144

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Great Comparison

145

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider146

4/17/15, 16:45ruby on rails - Minitest and Rspec - Stack Overflow

Page 1 of 1http://stackoverflow.com/questions/12470601/minitest-and-rspec

sign up log in tour help stack overflow careers

Take the 2-minute tour ×Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, noregistration required.

Minitest and Rspec [closed]

I have just watched a for Minitest.Railscast

What are the pros and cons for using RSpec vs Minitest for testing a rails app? Which features will I lose converting from RSpec to Minitest?

ruby-on-rails ruby testing rspec minitest

edited Aug 24 '13 at 14:16juanitofatas2,013 1 12 27

asked Sep 18 '12 at 4:55GTDev1,746 1 24 58

as not constructive by , , , , closed Abizern andrewsi Andrew Sean Cheshire ЯegDwight Sep 18 '12 at 19:40As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likelysolicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, for guidance.visit the help center

If this question can be reworded to fit the rules in the , please .help center edit the question

– See e.g. stackoverflow.com/questions/8423227/… matt Sep 18 '12 at 5:05

– Perhaps these 2 questions should be merged, is there a way of merging questions? Boris Stitnicky Sep18 '12 at 5:10

9 – Closed with +12 votes!!! voting to open. Anoop Vaidya Apr 18 '13 at 18:10

– the problem with close votes is that they are usually not very constructive... nus May 24 '14 at 1:45

2 Answers

I'm one of the RSpec developers, and have never used minitest, so take my biases intoaccount when reading this answer.

By and large, RSpec's power comes from the fact that it reifies so many testing concepts intofirst class objects. Where Test::Unit and Minitest use simple methods for making assertions,RSpec uses first-class matcher objects that support negation, self-description and more.RSpec's examples are first-class objects that support rich metadata; minitest/spec compiles

blocks down into simple methods, which don't support the same sort of rich metadata.RSpec supports specifying shared behaviors using a first-class construct (shared examplegroups) that accepts arguments; w/ minitest you can use

, but it doesn't have the same sort of first-class support. RSpec has an explicit formatterAPI (and there are many third party formatters that use it); I'm not aware of minitest having thesame sort of first-class formatter API.

it

inheritance or a mixin to re-usetests

As somebody who is constantly running tests and practicing TDD all day long, I find thepower RSpec gives me to be very useful. Many people find it to be overkill, though, and thereis an added cognitive cost to the extra abstractions.

Here are some specific features RSpec has that I believe minitest lacks:

hooks (note this is a power user feature of RSpec that should rarely beused; I've only used it on a few occasions in many years of using RSpec)before(:all)

hooksaround(:each)

Shared example groupsShared contextsRich metadata support that can be used to control which examples get run, whichexample groups shared contexts get included in, which example groups modules getmixed into and more.Integrated support for a wide range of mocking features w/ rspec-mocks; Minitest::Mockis far simpler and more limited in comparison.RSpec has , which is awesome.rspec-fire

Benefits of using Minitest:

It's built into the standard library so you don't need to install anything extra.It can either be used in or styles.def test_blah it 'blah'

The code base is very small and simple. RSpec, by virtue of it's older age and additionalfeatures, is larger in comparison.Minitest loads faster than RSpec (it's about 4 files of code compared to RSpec havingmany files spread across 3 gems)--but note that RSpec is by no means slow; in most ofmy projects these days, I get test feedback from RSpec in under a second (and often inunder 500 ms).

Overall, it's a bit like Sinatra vs. Rails, and I think Minitest and RSpec are both fine choicesdepending on your needs.

One last thing: if there are specific aspects of Minitest you like better, but other things you likebetter about RSpec, they can easily be mixed and matched. I , ifyou're interested.

wrote a blog post about this

answered Sep 18 '12 at 16:00Myron Marston11.3k 2 30 42

– Thanks for amazing explanation. Boris Stitnicky Sep 18 '12 at 16:14

2

Keep in mind Boris that if want to integrate MiniTest with Spork, Guard, Capybara, and any kind ofJavascript driver, you can plan on spending an entire week trying to figure it out and get it stable. MiniTestis not ready for primetime when it comes to having a complete testing stack for anything but the mostrudimentary of Rails applications. I gave it the old college try myself but it just ended in frustration.AKWF May 2 '13 at 19:58

I converted to spec-style Minitest from with , and it pays off. It doesaway with boilerplate and they say it also improves speed. I never really used RSpec. Instead,I wrote my own primitive testing and mocking framework (just for the purpose ofunderstanding mocking, I abandoned it upon switching to Minitest). I think thatstubbing/mocking in RSpec might be more advanced, so if you already learned it, justcontinue using it. Otherwise, stick with Minitest, which will enable you to collaborate withpeople ignorant of RSpec, such as me.

Test/Unit shoulda

edited Aug 12 '14 at 4:15 answered Sep 18 '12 at 5:07Boris Stitnicky6,632 2 23 45

by protected Tats_innit Sep 14 '14 at 6:37Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 on this site.

Would you like to answer one of these instead?

reputation

unanswered questions

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider146

4/17/15, 16:45ruby on rails - Minitest and Rspec - Stack Overflow

Page 1 of 1http://stackoverflow.com/questions/12470601/minitest-and-rspec

sign up log in tour help stack overflow careers

Take the 2-minute tour ×Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, noregistration required.

Minitest and Rspec [closed]

I have just watched a for Minitest.Railscast

What are the pros and cons for using RSpec vs Minitest for testing a rails app? Which features will I lose converting from RSpec to Minitest?

ruby-on-rails ruby testing rspec minitest

edited Aug 24 '13 at 14:16juanitofatas2,013 1 12 27

asked Sep 18 '12 at 4:55GTDev1,746 1 24 58

as not constructive by , , , , closed Abizern andrewsi Andrew Sean Cheshire ЯegDwight Sep 18 '12 at 19:40As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likelysolicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, for guidance.visit the help center

If this question can be reworded to fit the rules in the , please .help center edit the question

– See e.g. stackoverflow.com/questions/8423227/… matt Sep 18 '12 at 5:05

– Perhaps these 2 questions should be merged, is there a way of merging questions? Boris Stitnicky Sep18 '12 at 5:10

9 – Closed with +12 votes!!! voting to open. Anoop Vaidya Apr 18 '13 at 18:10

– the problem with close votes is that they are usually not very constructive... nus May 24 '14 at 1:45

2 Answers

I'm one of the RSpec developers, and have never used minitest, so take my biases intoaccount when reading this answer.

By and large, RSpec's power comes from the fact that it reifies so many testing concepts intofirst class objects. Where Test::Unit and Minitest use simple methods for making assertions,RSpec uses first-class matcher objects that support negation, self-description and more.RSpec's examples are first-class objects that support rich metadata; minitest/spec compiles

blocks down into simple methods, which don't support the same sort of rich metadata.RSpec supports specifying shared behaviors using a first-class construct (shared examplegroups) that accepts arguments; w/ minitest you can use

, but it doesn't have the same sort of first-class support. RSpec has an explicit formatterAPI (and there are many third party formatters that use it); I'm not aware of minitest having thesame sort of first-class formatter API.

it

inheritance or a mixin to re-usetests

As somebody who is constantly running tests and practicing TDD all day long, I find thepower RSpec gives me to be very useful. Many people find it to be overkill, though, and thereis an added cognitive cost to the extra abstractions.

Here are some specific features RSpec has that I believe minitest lacks:

hooks (note this is a power user feature of RSpec that should rarely beused; I've only used it on a few occasions in many years of using RSpec)before(:all)

hooksaround(:each)

Shared example groupsShared contextsRich metadata support that can be used to control which examples get run, whichexample groups shared contexts get included in, which example groups modules getmixed into and more.Integrated support for a wide range of mocking features w/ rspec-mocks; Minitest::Mockis far simpler and more limited in comparison.RSpec has , which is awesome.rspec-fire

Benefits of using Minitest:

It's built into the standard library so you don't need to install anything extra.It can either be used in or styles.def test_blah it 'blah'

The code base is very small and simple. RSpec, by virtue of it's older age and additionalfeatures, is larger in comparison.Minitest loads faster than RSpec (it's about 4 files of code compared to RSpec havingmany files spread across 3 gems)--but note that RSpec is by no means slow; in most ofmy projects these days, I get test feedback from RSpec in under a second (and often inunder 500 ms).

Overall, it's a bit like Sinatra vs. Rails, and I think Minitest and RSpec are both fine choicesdepending on your needs.

One last thing: if there are specific aspects of Minitest you like better, but other things you likebetter about RSpec, they can easily be mixed and matched. I , ifyou're interested.

wrote a blog post about this

answered Sep 18 '12 at 16:00Myron Marston11.3k 2 30 42

– Thanks for amazing explanation. Boris Stitnicky Sep 18 '12 at 16:14

2

Keep in mind Boris that if want to integrate MiniTest with Spork, Guard, Capybara, and any kind ofJavascript driver, you can plan on spending an entire week trying to figure it out and get it stable. MiniTestis not ready for primetime when it comes to having a complete testing stack for anything but the mostrudimentary of Rails applications. I gave it the old college try myself but it just ended in frustration.AKWF May 2 '13 at 19:58

I converted to spec-style Minitest from with , and it pays off. It doesaway with boilerplate and they say it also improves speed. I never really used RSpec. Instead,I wrote my own primitive testing and mocking framework (just for the purpose ofunderstanding mocking, I abandoned it upon switching to Minitest). I think thatstubbing/mocking in RSpec might be more advanced, so if you already learned it, justcontinue using it. Otherwise, stick with Minitest, which will enable you to collaborate withpeople ignorant of RSpec, such as me.

Test/Unit shoulda

edited Aug 12 '14 at 4:15 answered Sep 18 '12 at 5:07Boris Stitnicky6,632 2 23 45

by protected Tats_innit Sep 14 '14 at 6:37Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 on this site.

Would you like to answer one of these instead?

reputation

unanswered questions

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Apparently, I'm @tenderlove

147

https://farm4.staticflickr.com/3522/3274006022_0c72c24508_o.jpg

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Apparently, I'm @tenderlove

147

https://farm4.staticflickr.com/3522/3274006022_0c72c24508_o.jpg

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

TL;DR148

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider149

By and large, RSpec's power comes from the fact that it reifies so many testing concepts into first class objects. Where Test::Unit and Minitest use simple methods for making assertions, RSpec uses first-class matcher objects that support negation, self-description and more. RSpec's examples are first-class objects that support rich metadata; minitest/spec compiles it blocks down into simple methods, which don't support the same sort of rich metadata. RSpec supports specifying shared behaviors using a first-class construct (shared example groups) that accepts arguments; w/ minitest you can use inheritance or a mixin to re-use tests, but it doesn't have the same sort of first-class support.

http://stackoverflow.com/questions/12470601/minitest-and-rspec

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Myron thinks this is why RSpec is great

150

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

I think it is everything wrong with RSpec

151

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

We're Both Right

152

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

"Do I contradict myself? Very well, then I contradict myself, I am

large, I contain multitudes." —Walt Whitman

153

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider154

By and large, RSpec's power comes from the fact that it reifies so many testing concepts into first class objects. Where Test::Unit and Minitest use simple methods for making assertions, RSpec uses first-class matcher objects that support negation, self-description and more. RSpec's examples are first-class objects that support rich metadata; minitest/spec compiles it blocks down into simple methods, which don't support the same sort of rich metadata. RSpec supports specifying shared behaviors using a first-class construct (shared example groups) that accepts arguments; w/ minitest you can use inheritance or a mixin to re-use tests, but it doesn't have the same sort of first-class support.

http://stackoverflow.com/questions/12470601/minitest-and-rspec

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest RSpec

Example Groups

Examples

Reuse

Expectations

Minitest RSpec

155

* my interpretation, not a quote

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest RSpec

Example Groups

Examples

Reuse

Expectations

Minitest RSpec

Example Groups compiles describe blocks down into simple classes*

reifies testing concepts into first class objects*

155

* my interpretation, not a quote

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest RSpec

Example Groups

Examples

Reuse

Expectations

Minitest RSpec

Example Groups compiles describe blocks down into simple classes*

reifies testing concepts into first class objects*

Examples compiles it blocks down into simple methods

examples are first-class objects

155

* my interpretation, not a quote

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest RSpec

Example Groups

Examples

Reuse

Expectations

Minitest RSpec

Example Groups compiles describe blocks down into simple classes*

reifies testing concepts into first class objects*

Examples compiles it blocks down into simple methods

examples are first-class objects

Reuse you can use inheritance or a mixin

specifying shared behaviors using a first-class construct

155

* my interpretation, not a quote

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest RSpec

Example Groups

Examples

Reuse

Expectations

Minitest RSpec

Example Groups compiles describe blocks down into simple classes*

reifies testing concepts into first class objects*

Examples compiles it blocks down into simple methods

examples are first-class objects

Reuse you can use inheritance or a mixin

specifying shared behaviors using a first-class construct

Expectations use simple methods for making assertions

uses first-class matcher objects

155

* my interpretation, not a quote

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest RSpec

Example Groups compiles describe blocks down into simple methods

reifies testing concepts into first class objects

Examples compiles it blocks down into simple methods

examples are first-class objects

Reuse you can use inheritance or a mixin

specifying shared behaviors using a first-class construct

Expectations use simple methods for making assertions

uses first-class matcher objects

Minitest RSpec

156

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest RSpec

Example Groups compiles describe blocks down into simple methods

reifies testing concepts into first class objects

Examples compiles it blocks down into simple methods

examples are first-class objects

Reuse you can use inheritance or a mixin

specifying shared behaviors using a first-class construct

Expectations use simple methods for making assertions

uses first-class matcher objects

Minitest RSpec

Example Groups Class 1st Class Object

156

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest RSpec

Example Groups compiles describe blocks down into simple methods

reifies testing concepts into first class objects

Examples compiles it blocks down into simple methods

examples are first-class objects

Reuse you can use inheritance or a mixin

specifying shared behaviors using a first-class construct

Expectations use simple methods for making assertions

uses first-class matcher objects

Minitest RSpec

Example Groups Class 1st Class Object

Examples Method 1st Class Object

156

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest RSpec

Example Groups compiles describe blocks down into simple methods

reifies testing concepts into first class objects

Examples compiles it blocks down into simple methods

examples are first-class objects

Reuse you can use inheritance or a mixin

specifying shared behaviors using a first-class construct

Expectations use simple methods for making assertions

uses first-class matcher objects

Minitest RSpec

Example Groups Class 1st Class Object

Examples Method 1st Class Object

Reuse Subclass or Include 1st Class Object

156

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest RSpec

Example Groups compiles describe blocks down into simple methods

reifies testing concepts into first class objects

Examples compiles it blocks down into simple methods

examples are first-class objects

Reuse you can use inheritance or a mixin

specifying shared behaviors using a first-class construct

Expectations use simple methods for making assertions

uses first-class matcher objects

Minitest RSpec

Example Groups Class 1st Class Object

Examples Method 1st Class Object

Reuse Subclass or Include 1st Class Object

Expectations Method Call 1st Class Object

156

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider157

“1st Class”You keep using that term. I do not think it means what you think it means.

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

A language construct is said to be a FirstClass value in that language when there are no restrictions on how it can be created and used: when

the construct can be treated as a value without restrictions.

FirstClass features can be stored in variables, passed as arguments to functions, created within functions and returned from functions. In

dynamically typed languages, a FirstClass feature can also have its type examined at run-time.

http://c2.com/cgi/wiki?FirstClass

158

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest RSpec

Example Groups Class 1st Class Object

Examples Method 1st Class Object

Reuse Subclass or Include 1st Class Object

Expectations Method Call 1st Class Object

159

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest RSpec

Example Groups Class 1st Class Object

Examples Method 1st Class Object

Reuse Subclass or Include 1st Class Object

Expectations Method Call 1st Class Object

159

It's Just Ruby™

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest RSpec

Example Groups Class 1st Class Object

Examples Method 1st Class Object

Reuse Subclass or Include 1st Class Object

Expectations Method Call 1st Class Object

159

It's Just Ruby™

Reinvents the Wheel

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Nested Describesdescribe A do before { :a } it "runs :a"

describe B do before { :b } it "runs :a, :b" end end

160

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Nested Describesdescribe A do before { :a } it "runs :a"

describe B do before { :b } it "runs :a, :b" end end

160

Inherited "methods"

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Nested Describesdescribe A do before { :a } it "runs :a"

describe B do before { :b } it "runs :a, :b" end end

160

Inherited "methods"

NOT Inherited "methods"

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Are A & B classes? Is Nesting like Subclassing?

161

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Classes?class TestA < RSpec::Spec def before super :a end

def test_runs_a; end end

class TestB < TestA def before super :b end

undef_method :test_runs_a

def test_runs_a_b; end end

162

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Classes?class TestA < RSpec::Spec def before super :a end

def test_runs_a; end end

class TestB < TestA def before super :b end

undef_method :test_runs_a

def test_runs_a_b; end end

162

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Are before/after like included modules?

163

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Modules?class TestA < RSpec::Spec module BeforeAfter def setup super if respond_to? :super :a end end

include TestA::BeforeAfter

def test_runs_a; end end

class TestB < RSpec::Spec module BeforeAfter def setup super if respond_to? :super :b end end

include TestA::BeforeAfter include TestB::BeforeAfter

def test_runs_a_b; end end

164

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

This is basically Another Object Model

165

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

That's Confusing if you're just learning

Ruby/OO166

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Encourages new users to handwave

167

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

To not know what #describe or #it actually are or do

168

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

“Here's the Magic Incantation to do X”

169

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

“Any sufficiently advanced technology is indistinguishable

from magic.” —A.C. Clarke

170

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

RSpec: It’s actually Magic

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider172

“Many people find it to be overkill, though, and there is an added cognitive cost to the extra abstractions.”

—Myron Marsten, from previous post

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Indeed173

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider174

*/lib Minitest RSpec Multiplier# Files 14 177 12.64Flog 2,005.0 13,274.3 6.62

Lines of Code 1,589 15,095 9.50Lines of Comment 1,063 7,566 7.12Comment + Code 2,652 22,661 8.54Comment/Code 0.66 0.50 N/A

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider175

0.0

3500.0

7000.0

10500.0

14000.0

Minitest RSpec

Flog

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider176

0

7,500

15,000

22,500

30,000

Minitest RSpec

Lines of Code Lines of Comment

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider177

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider177

TEST

TEST

TEST

TEST

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

vs177

TEST

TEST

TEST

TEST

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

vs177

TEST

TEST

TEST

TEST

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider178

“Many people find it to be overkill, though, and there is an added cognitive cost to the extra abstractions.”

—Myron Marsten, from previous post

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Not just cognitive!

179

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Performance differences with

RSpec180

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

All those abstractions?

181

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Reinventing the wheel?

182

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Has a Real Cost183

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Combined Minitest Results

Mem

ory

(MB)

0.00

25.00

50.00

75.00

100.00

Tim

e (s

)

0.00

0.45

0.90

1.35

1.80

# tests

500 1500 2500 3500 4500 5500 6500 7500 8500 9500

pos mt time pos mt memory1neg mt time 1neg mt memory50neg mt time 50neg mt memory100neg mt time 100neg mt memory

184

Combined RSpec Results

Mem

ory

(MB)

0.00

75.00

150.00

225.00

300.00

Tim

e (s

)

0.00

25.00

50.00

75.00

100.00

# tests

500 1500 2500 3500 4500 5500 6500 7500 8500 9500

pos rs time pos rs memory1neg rs time 1neg rs memory50neg rs time 50neg rs memory100neg rs time 100neg rs memory

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Combined RSpec Results

Mem

ory

(MB)

0.00

75.00

150.00

225.00

300.00

Tim

e (s

)

0.00

25.00

50.00

75.00

100.00

# tests

500 1500 2500 3500 4500 5500 6500 7500 8500 9500

pos rs time pos rs memory1neg rs time 1neg rs memory50neg rs time 50neg rs memory100neg rs time 100neg rs memory

Combined Minitest Results

Mem

ory

(MB)

0.00

75.00

150.00

225.00

300.00

Tim

e (s

)

0.08

25.06

50.04

75.02

100.00

# tests

500 1500 2500 3500 4500 5500 6500 7500 8500 9500

pos mt time pos mt memory1neg mt time 1neg mt memory50neg mt time 50neg mt memory100neg mt time 100neg mt memory

185

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

But Ryan...186

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Who cares?187

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Passing rspec is fast enough

188

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Bug?

189

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Bug?Refactor?

189

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Bug?Refactor?

Anything else goes wrong?189

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

You Pay190

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

For Completeness:

191

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Expectation Speed

192

Minitest vs RSpec, time & memory (assertions)

Tim

e (s

)

0.00

0.15

0.30

0.45

0.60

1 test, # assertions

1000

6000

1100

016

000

2100

026

000

3100

036

000

4100

046

00050

000

mt timers time

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Minitest vs RSpec, time

Tim

e (s

)

0.00

2.25

4.50

6.75

9.00

# tests, 0 assertions

1000

5000

9000

1300

017

00021

00025

00029

00033

00037

00041

00045

00049

000

mt timers time Method

Execution Speed

193

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Linear194

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Don't reduce examples or expectations

195

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

If you want a speed up

196

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Switch to minitest

197

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Or never, ever refactor.

198

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Summary199

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

At the end of the day…

200

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

As long as you test

201

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

I don't care what you use

202

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Use the best tool for your job

203

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Hopefully, I've shown

204

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

The technical merits of Minitest

205

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Choose what works for you

206

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Not because it seems popular

207

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Maybe there's fewer articles about MT because there's less need for them?

208

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

MT is much easier to understand.

209

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

MT users aren't missing.

210

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

They're busy Getting Stuff Done.

211

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Choose what works for you

212

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Who knows?213

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Try It214

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

You might like it

215

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

After All216

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

It's Just Ruby™217

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Thank You218

Ruby on Rails on Minitest

RailsConf 2015, Atlanta, GA

Ryan Davis, Seattle.rb 

@the_zenspider

Thank You(hire me)

218