Minitest & Rails: Total BFFs

Minitest & Rails: Total BFFs

Rails 4 is switching to MiniTest from Test::Unit. What does this mean for you? MiniTest is more than an exercise in minimalism, it’s a full-featured testing framework. Using MiniTest, we can change our approach to application design and build Rails apps that are more flexible, easier to refactor, and more maintainable.

We’ll get straight to the good stuff: How to test validations. When to stub and when to mock. How to use fixtures, and when you should skip them. Can your model tests be faster? What about controller tests? And why you’d choose it over RSpec.

Have you worked on apps where the tests are mocked to the hilt and impossible to change when refactoring? Or wasted time hunting through dozens of files to find all the downstream methods called from one controller action? Or simply thrown tests away because your team can no longer maintain them? Then this session is for you.

Cd8da976054ea4915eafc5d9dd096d38?s=128

blowmage

May 13, 2013
Tweet

Transcript

  1. Minitest & Rails

  2. Minitest & Rails

  3. Minitest & Rails Total BFFs

  4. Let me tell you a story...

  5. None
  6. None
  7. Minitest is replacing Test::Unit in Rails 4

  8. None
  9. How does minitest work?

  10. None
  11. I’ll show you!

  12. Example Test

  13. class Pony def friendship "magic" end end test/pony_test.rb

  14. # class Pony # def friendship # "magic" # end

    # end test/pony_test.rb
  15. require "minitest/autorun" # class Pony # def friendship # "magic"

    # end # end test/pony_test.rb
  16. require "minitest/autorun" # class Pony # def friendship # "magic"

    # end # end class PonyTest < Minitest::Test end test/pony_test.rb
  17. require "minitest/autorun" # class Pony # def friendship # "magic"

    # end # end class PonyTest < Minitest::Test def test_friendship end end test/pony_test.rb
  18. require "minitest/autorun" # class Pony # def friendship # "magic"

    # end # end class PonyTest < Minitest::Test def test_friendship assert(Pony.new.friendship == "magic") end end test/pony_test.rb
  19. require "minitest/autorun" # class Pony # def friendship # "magic"

    # end # end class PonyTest < Minitest::Test def test_friendship assert(Pony.new.friendship == "magic") end end test/pony_test.rb $ ruby test/pony_test.rb Run options: --seed 49523 # Running: E Finished in 0.000875s, 1142.8571 runs/s, 0.0000 assertions/s. 1) Error: PonyTest#test_friendship: NameError: uninitialized constant PonyTest::Pony test/pony_test.rb:11:in `test_friendship' 1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
  20. require "minitest/autorun" # class Pony # def friendship # "magic"

    # end # end class PonyTest < Minitest::Test def test_friendship assert(Pony.new.friendship == "magic") end end test/pony_test.rb $ ruby test/pony_test.rb Run options: --seed 49523 # Running: E Finished in 0.000875s, 1142.8571 runs/s, 0.0000 assertions/s. 1) Error: PonyTest#test_friendship: NameError: uninitialized constant PonyTest::Pony test/pony_test.rb:11:in `test_friendship' 1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
  21. require "minitest/autorun" class Pony # def friendship # "magic" #

    end end class PonyTest < Minitest::Test def test_friendship assert(Pony.new.friendship == "magic") end end test/pony_test.rb
  22. require "minitest/autorun" class Pony # def friendship # "magic" #

    end end class PonyTest < Minitest::Test def test_friendship assert(Pony.new.friendship == "magic") end end test/pony_test.rb $ ruby test/pony_test.rb Run options: --seed 58892 # Running: E Finished in 0.000793s, 1261.0340 runs/s, 0.0000 assertions/s. 1) Error: PonyTest#test_friendship: NoMethodError: undefined method `friendship' for #<Pony:0x007fda26909db0> test/pony_test.rb:11:in `test_friendship' 1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
  23. require "minitest/autorun" class Pony def friendship # "magic" end end

    class PonyTest < Minitest::Test def test_friendship assert(Pony.new.friendship == "magic") end end test/pony_test.rb
  24. require "minitest/autorun" class Pony def friendship # "magic" end end

    class PonyTest < Minitest::Test def test_friendship assert(Pony.new.friendship == "magic") end end test/pony_test.rb $ ruby test/pony_test.rb Run options: --seed 17894 # Running: F Finished in 0.000805s, 1242.2360 runs/s, 1242.2360 assertions/s. 1) Failure: PonyTest#test_friendship [test/pony_test.rb:11]: Failed assertion, no message given. 1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
  25. require "minitest/autorun" class Pony def friendship "magic" end end class

    PonyTest < Minitest::Test def test_friendship assert(Pony.new.friendship == "magic") end end test/pony_test.rb
  26. require "minitest/autorun" class Pony def friendship "magic" end end class

    PonyTest < Minitest::Test def test_friendship assert(Pony.new.friendship == "magic") end end test/pony_test.rb $ ruby test/pony_test.rb Run options: --seed 3512 # Running: . Finished in 0.000799s, 1251.5645 runs/s, 1251.5645 assertions/s. 1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
  27. require "minitest/autorun" class Pony def friendship "magic" end end class

    PonyTest < Minitest::Test def test_friendship assert(Pony.new.friendship == "magic") end end test/pony_test.rb $ ruby test/pony_test.rb Run options: --seed 3512 # Running: . Finished in 0.000799s, 1251.5645 runs/s, 1251.5645 assertions/s. 1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
  28. But Pinkie!

  29. But Pinkie! That assertion message was kinda ugly, right?

  30. require "minitest/autorun" class Pony def friendship # "magic" end end

    class PonyTest < Minitest::Test def test_friendship assert(Pony.new.friendship == "magic") end end test/pony_test.rb
  31. require "minitest/autorun" class Pony def friendship # "magic" end end

    class PonyTest < Minitest::Test def test_friendship assert(Pony.new.friendship == "magic") end end test/pony_test.rb $ ruby test/pony_test.rb Run options: --seed 17894 # Running: F Finished in 0.000805s, 1242.2360 runs/s, 1242.2360 assertions/s. 1) Failure: PonyTest#test_friendship [test/pony_test.rb:11]: Failed assertion, no message given. 1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
  32. require "minitest/autorun" class Pony def friendship # "magic" end end

    class PonyTest < Minitest::Test def test_friendship assert(Pony.new.friendship == "magic") end end test/pony_test.rb
  33. require "minitest/autorun" class Pony def friendship # "magic" end end

    class PonyTest < Minitest::Test def test_friendship assert((Pony.new.friendship == "magic"), "Friendship expected to be magic") end end test/pony_test.rb
  34. require "minitest/autorun" class Pony def friendship # "magic" end end

    class PonyTest < Minitest::Test def test_friendship assert((Pony.new.friendship == "magic"), "Friendship expected to be magic") end end test/pony_test.rb $ ruby test/pony_test.rb Run options: --seed 28853 # Running: F Finished in 0.000787s, 1270.6480 runs/s, 1270.6480 assertions/s. 1) Failure: PonyTest#test_friendship [test/pony_test.rb:11]: Friendship expected to be magic 1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
  35. require "minitest/autorun" class Pony def friendship # "magic" end end

    class PonyTest < Minitest::Test def test_friendship assert_equal "magic", Pony.new.friendship end end test/pony_test.rb
  36. require "minitest/autorun" class Pony def friendship # "magic" end end

    class PonyTest < Minitest::Test def test_friendship assert_equal "magic", Pony.new.friendship end end test/pony_test.rb $ ruby test/pony_test.rb Run options: --seed 53489 # Running: F Finished in 0.028344s, 35.2808 runs/s, 35.2808 assertions/s. 1) Failure: PonyTest#test_friendship [test/pony_test.rb:11]: Expected: "magic" Actual: nil 1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
  37. require "minitest/autorun" class Pony def friendship "magic" end end class

    PonyTest < Minitest::Test def test_friendship assert_equal "magic", Pony.new.friendship end end test/pony_test.rb
  38. require "minitest/autorun" class Pony def friendship "magic" end end class

    PonyTest < Minitest::Test def test_friendship assert_equal "magic", Pony.new.friendship end end test/pony_test.rb $ ruby test/pony_test.rb Run options: --seed 13305 # Running: . Finished in 0.000884s, 1131.2217 runs/s, 1131.2217 assertions/s. 1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
  39. require "minitest/autorun" class Pony def friendship "magic" end end class

    PonyTest < Minitest::Test def test_friendship assert_equal "magic", Pony.new.friendship end end test/pony_test.rb $ ruby test/pony_test.rb Run options: --seed 13305 # Running: . Finished in 0.000884s, 1131.2217 runs/s, 1131.2217 assertions/s. 1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
  40. TDD Process

  41. TDD Process •Test Class

  42. TDD Process •Test Class •Test Method

  43. TDD Process •Test Class •Test Method •Assertion

  44. TDD Process •Test Class •Test Method •Assertion •Error

  45. TDD Process •Test Class •Test Method •Assertion •Error •Failure

  46. TDD Process •Test Class •Test Method •Assertion •Error •Failure •Pass

  47. TDD Process •Test Class •Test Method •Assertion •Error •Failure •Pass

    •Refactor
  48. Testing Models

  49. class Pony def friendship "magic" end end app/models/pony.rb

  50. class Pony < ActiveRecord::Base def friendship "magic" end end app/models/pony.rb

  51. require "minitest/autorun" class PonyTest < Minitest::Test def test_friendship assert_equal "magic",

    Pony.new.friendship end end test/pony_test.rb
  52. require 'test_helper' class PonyTest < ActiveSupport::TestCase def test_friendship assert_equal "magic",

    Pony.new.friendship end end app/models/pony.rb
  53. require 'test_helper' class PonyTest < ActiveSupport::TestCase def twilight @twilight ||=

    Pony.new name: "Twilight Sparkle" end def test_name assert_equal "Twilight Sparkle", twilight.name end def test_friendship assert_equal "magic", twilight.friendship end end app/models/pony.rb
  54. require 'test_helper' class PonyTest < ActiveSupport::TestCase def twilight @twilight ||=

    Pony.new name: "Twilight Sparkle" end def test_name assert_equal "Twilight Sparkle", twilight.name end def test_friendship assert_equal "magic", twilight.friendship end end app/models/pony.rb
  55. ActiveSupport::TestCase

  56. ActiveSupport::TestCase •Per-test database transactions

  57. ActiveSupport::TestCase •Per-test database transactions •Fixtures

  58. ActiveSupport::TestCase •Per-test database transactions •Fixtures •assert_blank

  59. ActiveSupport::TestCase •Per-test database transactions •Fixtures •assert_blank •assert_present

  60. ActiveSupport::TestCase •Per-test database transactions •Fixtures •assert_blank •assert_present •assert_difference

  61. ActiveSupport::TestCase •Per-test database transactions •Fixtures •assert_blank •assert_present •assert_difference •assert_no_difference

  62. But Pinkie!

  63. But Pinkie! What are fixtures?

  64. require 'test_helper' class PonyTest < ActiveSupport::TestCase def twilight @twilight ||=

    Pony.new name: "Twilight Sparkle" end def test_name assert_equal "Twilight Sparkle", twilight.name end def test_friendship assert_equal "magic", twilight.friendship end end app/models/pony.rb
  65. require 'test_helper' class PonyTest < ActiveSupport::TestCase def twilight @twilight ||=

    Pony.new name: "Twilight Sparkle" end def test_name assert_equal "Twilight Sparkle", twilight.name end def test_friendship assert_equal "magic", twilight.friendship end end app/models/pony.rb
  66. twilight: name: Twilight Sparkle email: twilight@ponyville.com pinkie: name: Pinkie Pie

    email: pinkie@ponyville.com test/fixtures/ponies.yml
  67. sprinkle: name: Twinkle Sprinkle fluffy: name: Fluffy Top test/fixtures/cupcakes.yml

  68. twilight_sprinkle: pony: twilight cupcake: sprinkle pinkie_fluffy: pony: pinkie cupcake: fluffy

    test/fixtures/favorites.yml
  69. require 'test_helper' class PonyTest < ActiveSupport::TestCase def twilight @twilight ||=

    Pony.new name: "Twilight Sparkle" end def test_name assert_equal "Twilight Sparkle", twilight.name end def test_friendship assert_equal "magic", twilight.friendship end end app/models/pony.rb
  70. require 'test_helper' class PonyTest < ActiveSupport::TestCase def twilight @twilight ||=

    Pony.new name: "Twilight Sparkle" end def test_name assert_equal "Twilight Sparkle", twilight.name end def test_friendship assert_equal "magic", twilight.friendship end end app/models/pony.rb
  71. require 'test_helper' class PonyTest < ActiveSupport::TestCase def twilight @twilight ||=

    ponies(:twilight) end def test_name assert_equal "Twilight Sparkle", twilight.name end def test_friendship assert_equal "magic", twilight.friendship end end app/models/pony.rb
  72. require 'test_helper' class PonyTest < ActiveSupport::TestCase def twilight @twilight ||=

    ponies(:twilight) end def test_name assert_equal "Twilight Sparkle", twilight.name end def test_friendship assert_equal "magic", twilight.friendship end end app/models/pony.rb $ ruby test/pony_test.rb Run options: --seed 13305 # Running: . Finished in 0.000884s, 1131.2217 runs/s, 1131.2217 assertions/s. 1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
  73. Testing Controllers

  74. test/controllers/cupcakes_test.rb require "test_helper" class CupcakesControllerTest < ActionController::TestCase def test_index get

    :index assert_response :success end def test_show get :show, id: cupcakes(:sprinkle) assert_response :success end end
  75. test/controllers/cupcakes_test.rb require "test_helper" class CupcakesControllerTest < ActionController::TestCase def test_index get

    :index assert_response :success end def test_show get :show, id: cupcakes(:sprinkle) assert_response :success end end $ rake test:controllers Run options: --seed 22699 # Running tests: .. Finished tests in 0.124348s, 16.0839 tests/s, 16.0839 assertions/s. 2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
  76. ActionController::TestCase

  77. ActionController::TestCase •request

  78. ActionController::TestCase •request •response

  79. ActionController::TestCase •request •response •session

  80. ActionController::TestCase •request •response •session •flash

  81. ActionController::TestCase •request •response •session •flash •assert_response

  82. ActionController::TestCase •request •response •session •flash •assert_response •assert_redirected_to

  83. ActionController::TestCase •request •response •session •flash •assert_response •assert_redirected_to •assert_template

  84. Testing Helpers

  85. module CupcakesHelper def cupcake_image_tag cupcake image_tag cupcake.image_url, alt: cupcake.name end

    end app/helpers/cupcakes_helper.rb
  86. require 'test_helper' class CupcakesHelperTest < ActionView::TestCase def setup @cupcake =

    Cupcake.new name: "Icy McIcerson", image_url: "http://i.imgur.com/mbWH1gM.png" end def test_alt_text image_tag_html = cupcake_image_tag @cupcake assert_match @cupcake.name, image_tag_html end def test_image_url image_tag_html = cupcake_image_tag @cupcake assert_match @cupcake.image_url, image_tag_html end end test/helpers/cupcakes_helper_test.rb
  87. require 'test_helper' class CupcakesHelperTest < ActionView::TestCase def setup @cupcake =

    Cupcake.new name: "Icy McIcerson", image_url: "http://i.imgur.com/mbWH1gM.png" end def test_alt_text image_tag_html = cupcake_image_tag @cupcake assert_match @cupcake.name, image_tag_html end def test_image_url image_tag_html = cupcake_image_tag @cupcake assert_match @cupcake.image_url, image_tag_html end end test/helpers/cupcakes_helper_test.rb $ rake test:helpers Run options: --seed 59089 # Running tests: .. Finished tests in 0.051314s, 38.9757 tests/s, 77.9514 assertions/s. 2 tests, 4 assertions, 0 failures, 0 errors, 0 skips
  88. require 'test_helper' class CupcakesHelperTest < ActionView::TestCase def setup @cupcake =

    Cupcake.new name: "Icy McIcerson", image_url: "http://i.imgur.com/mbWH1gM.png" end def test_alt_text image_tag_html = cupcake_image_tag @cupcake assert_match @cupcake.name, image_tag_html end def test_image_url image_tag_html = cupcake_image_tag @cupcake assert_match @cupcake.image_url, image_tag_html end def test_blank_image_url @cupcake.image_url = nil image_tag_html = cupcake_image_tag @cupcake assert_match Cupcake::DEFAULT_IMAGE_URL, image_tag_html end end test/helpers/cupcakes_helper_test.rb
  89. require 'test_helper' class CupcakesHelperTest < ActionView::TestCase def setup @cupcake =

    Cupcake.new name: "Icy McIcerson", image_url: "http://i.imgur.com/mbWH1gM.png" end def test_alt_text image_tag_html = cupcake_image_tag @cupcake assert_match @cupcake.name, image_tag_html end def test_image_url image_tag_html = cupcake_image_tag @cupcake assert_match @cupcake.image_url, image_tag_html end def test_blank_image_url @cupcake.image_url = nil image_tag_html = cupcake_image_tag @cupcake assert_match Cupcake::DEFAULT_IMAGE_URL, image_tag_html end end test/helpers/cupcakes_helper_test.rb $ rake test:helpers Run options: --seed 23417 # Running tests: .E. Finished tests in 0.050823s, 59.0284 tests/s, 78.7045 assertions/s. 1) Error: CupcakesHelperTest#test_blank_image_url: NameError: uninitialized constant Cupcake::DEFAULT_IMAGE_URL app/helpers/cupcakes_helper.rb:5:in `cupcake_image_tag' test/helpers/cupcakes_helper_test.rb:22:in `test_blank_image_url' 3 tests, 4 assertions, 0 failures, 1 errors, 0 skips
  90. class Cupcake < ActiveRecord::Base has_many :favorites has_many :ponies, through: :favorites

    end app/models/cupcake.rb
  91. class Cupcake < ActiveRecord::Base DEFAULT_IMAGE_URL = "/images/cupcake.png" has_many :favorites has_many

    :ponies, through: :favorites end app/models/cupcake.rb
  92. class Cupcake < ActiveRecord::Base DEFAULT_IMAGE_URL = "/images/cupcake.png" has_many :favorites has_many

    :ponies, through: :favorites end app/models/cupcake.rb $ rake test:helpers Run options: --seed 52680 # Running tests: .F. Finished tests in 0.028242s, 106.2248 tests/s, 212.4495 assertions/s. 1) Failure: CupcakesHelperTest#test_blank_image_url [~/pinkie_shop/test/helpers/ cupcakes_helper_test.rb:23]: Expected /\/images\/cupcake\.png/ to match "<img alt=\"Icy McIcerson\" src= \"\" />". 3 tests, 6 assertions, 1 failures, 0 errors, 0 skips
  93. module CupcakesHelper def cupcake_image_tag cupcake image_tag cupcake.image_url, alt: cupcake.name end

    end app/helpers/cupcakes_helper.rb
  94. module CupcakesHelper def cupcake_image_tag cupcake url = cupcake.image_url url =

    Cupcake::DEFAULT_IMAGE_URL if url.blank? image_tag url, alt: cupcake.name end end app/helpers/
  95. module CupcakesHelper def cupcake_image_tag cupcake url = cupcake.image_url url =

    Cupcake::DEFAULT_IMAGE_URL if url.blank? image_tag url, alt: cupcake.name end end app/helpers/ $ rake test:helpers Run options: --seed 32226 # Running tests: ... Finished tests in 0.049226s, 60.9434 tests/s, 121.8868 assertions/s. 3 tests, 6 assertions, 0 failures, 0 errors, 0 skips
  96. require 'test_helper' class CupcakesHelperTest < ActionView::TestCase def setup @cupcake =

    Cupcake.new name: "Icy McIcerson", image_url: "http://i.imgur.com/mbWH1gM.png" end def test_alt_text image_tag_html = cupcake_image_tag @cupcake assert_match @cupcake.name, image_tag_html end def test_image_url image_tag_html = cupcake_image_tag @cupcake assert_match @cupcake.image_url, image_tag_html end def test_blank_image_url @cupcake.image_url = nil image_tag_html = cupcake_image_tag @cupcake assert_match Cupcake::DEFAULT_IMAGE_URL, image_tag_html end end test/helpers/cupcakes_helper_test.rb
  97. require 'test_helper' class CupcakesHelperTest < ActionView::TestCase def setup @cupcake =

    Cupcake.new name: "Icy McIcerson", image_url: "http://i.imgur.com/mbWH1gM.png" end def test_alt_text image_tag_html = cupcake_image_tag @cupcake assert_match "alt=\"#{@cupcake.name}\"", image_tag_html end def test_image_url image_tag_html = cupcake_image_tag @cupcake assert_match "src=\"#{@cupcake.image_url}\"", image_tag_html end def test_blank_image_url @cupcake.image_url = nil image_tag_html = cupcake_image_tag @cupcake assert_match "src=\"#{Cupcake::DEFAULT_IMAGE_URL}\"", image_tag_html end end test/helpers/cupcakes_helper_test.rb
  98. require 'test_helper' class CupcakesHelperTest < ActionView::TestCase def setup @cupcake =

    Cupcake.new name: "Icy McIcerson", image_url: "http://i.imgur.com/mbWH1gM.png" end def test_alt_text image_tag_html = cupcake_image_tag @cupcake assert_match "alt=\"#{@cupcake.name}\"", image_tag_html end def test_image_url image_tag_html = cupcake_image_tag @cupcake assert_match "src=\"#{@cupcake.image_url}\"", image_tag_html end def test_blank_image_url @cupcake.image_url = nil image_tag_html = cupcake_image_tag @cupcake assert_match "src=\"#{Cupcake::DEFAULT_IMAGE_URL}\"", image_tag_html end end test/helpers/cupcakes_helper_test.rb $ rake test:helpers Run options: --seed 63012 # Running tests: ... Finished tests in 0.048934s, 61.3071 tests/s, 122.6141 assertions/s. 3 tests, 6 assertions, 0 failures, 0 errors, 0 skips
  99. Integration/Acceptance Tests

  100. None
  101. But Pinkie!

  102. But Pinkie! I really like the spec DSL... Can I

    still use it?
  103. app/models/pony.rb class Pony < ActiveRecord::Base has_many :favorites has_many :cupcakes, through:

    :favorites has_many :orders def friendship "magic" end end
  104. test/models/pony_test.rb require "test_helper" class PonyTest < ActiveSupport::TestCase def twilight_sparkle @twilight_sparkle

    ||= Pony.new name: "Twilight Sparkle" end def test_name assert_equal "Twilight Sparkle", twilight_sparkle.name end def test_friendship assert_equal "magic", twilight_sparkle.friendship end end
  105. test/test_helper.rb ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class

    ActiveSupport::TestCase ActiveRecord::Migration.check_pending! # Setup all fixtures in test/fixtures/*.yml for all tests in... # # Note: You'll currently still have to declare fixtures explicitly... # -- they do not yet inherit this setting fixtures :all # Add more helper methods to be used by all tests here... end
  106. test/test_helper.rb ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require

    "minitest/spec" class ActiveSupport::TestCase ActiveRecord::Migration.check_pending! # Setup all fixtures in test/fixtures/*.yml for all tests in... # # Note: You'll currently still have to declare fixtures explicitly... # -- they do not yet inherit this setting fixtures :all # Add more helper methods to be used by all tests here... extend Minitest::Spec::DSL register_spec_type(self) do |desc| desc < ActiveRecord::Base if desc.is_a?(Class) end end
  107. test/test_helper.rb ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require

    "minitest/spec" class ActiveSupport::TestCase ActiveRecord::Migration.check_pending! # Setup all fixtures in test/fixtures/*.yml for all tests in... # # Note: You'll currently still have to declare fixtures explicitly... # -- they do not yet inherit this setting fixtures :all # Add more helper methods to be used by all tests here... extend Minitest::Spec::DSL register_spec_type(self) do |desc| desc < ActiveRecord::Base if desc.is_a?(Class) end end
  108. require "test_helper" class PonyTest < ActiveSupport::TestCase def twilight_sparkle @twilight_sparkle ||=

    Pony.new name: "Twilight Sparkle" end def test_name assert_equal "Twilight Sparkle", twilight_sparkle.name end def test_friendship assert_equal "magic", twilight_sparkle.friendship end end test/models/pony_test.rb
  109. require "test_helper" describe Pony do def twilight_sparkle @twilight_sparkle ||= Pony.new

    name: "Twilight Sparkle" end def test_name assert_equal "Twilight Sparkle", twilight_sparkle.name end def test_friendship assert_equal "magic", twilight_sparkle.friendship end end test/models/pony_test.rb
  110. require "test_helper" describe Pony do def twilight_sparkle @twilight_sparkle ||= Pony.new

    name: "Twilight Sparkle" end def test_name assert_equal "Twilight Sparkle", twilight_sparkle.name end def test_friendship assert_equal "magic", twilight_sparkle.friendship end end test/models/pony_test.rb
  111. require "test_helper" describe Pony do def twilight_sparkle @twilight_sparkle ||= Pony.new

    name: "Twilight Sparkle" end it "knows it's name" do assert_equal "Twilight Sparkle", twilight_sparkle.name end it "knows about friendship" do assert_equal "magic", twilight_sparkle.friendship end end test/models/pony_test.rb
  112. require "test_helper" describe Pony do def twilight_sparkle @twilight_sparkle ||= Pony.new

    name: "Twilight Sparkle" end it "knows it's name" do assert_equal "Twilight Sparkle", twilight_sparkle.name end it "knows about friendship" do assert_equal "magic", twilight_sparkle.friendship end end test/models/pony_test.rb
  113. require "test_helper" describe Pony do def twilight_sparkle @twilight_sparkle ||= Pony.new

    name: "Twilight Sparkle" end it "knows it's name" do twilight_sparkle.name.must_equal "Twilight Sparkle" end it "knows about friendship" do twilight_sparkle.friendship.must_equal "magic" end end test/models/pony_test.rb
  114. require "test_helper" describe Pony do def twilight_sparkle @twilight_sparkle ||= Pony.new

    name: "Twilight Sparkle" end it "knows it's name" do twilight_sparkle.name.must_equal "Twilight Sparkle" end it "knows about friendship" do twilight_sparkle.friendship.must_equal "magic" end end test/models/pony_test.rb
  115. require "test_helper" describe Pony do let(:twilight_sparkle) { Pony.new name: "Twilight

    Sparkle" } it "knows it's name" do twilight_sparkle.name.must_equal "Twilight Sparkle" end it "knows about friendship" do twilight_sparkle.friendship.must_equal "magic" end end test/models/pony_test.rb
  116. require "test_helper" describe Pony do let(:twilight_sparkle) { Pony.new name: "Twilight

    Sparkle" } it "knows it's name" do twilight_sparkle.name.must_equal "Twilight Sparkle" end it "knows about friendship" do twilight_sparkle.friendship.must_equal "magic" end end test/models/pony_test.rb
  117. require "test_helper" class PonyTest < ActiveSupport::TestCase def twilight_sparkle @twilight_sparkle ||=

    Pony.new name: "Twilight Sparkle" end def test_name assert_equal "Twilight Sparkle", twilight_sparkle.name end def test_friendship assert_equal "magic", twilight_sparkle.friendship end end test/models/pony_test.rb
  118. require "test_helper" describe Pony do let(:twilight_sparkle) { Pony.new name: "Twilight

    Sparkle" } it "knows it's name" do twilight_sparkle.name.must_equal "Twilight Sparkle" end it "knows about friendship" do twilight_sparkle.friendship.must_equal "magic" end end test/models/pony_test.rb
  119. require "test_helper" describe Pony do let(:twilight_sparkle) { Pony.new name: "Twilight

    Sparkle" } it "knows it's name" do twilight_sparkle.name.must_equal "Twilight Sparkle" end it "knows about friendship" do twilight_sparkle.friendship.must_equal "magic" end end test/models/pony_test.rb
  120. test/controllers/cupcakes_test.rb require "test_helper" class CupcakesControllerTest < ActionController::TestCase def test_index get

    :index assert_response :success end def test_show get :show, id: cupcakes(:sprinkle) assert_response :success end end
  121. test/controllers/cupcakes_test.rb require "test_helper" describe CupcakesController do it 'shows a list

    of cupcakes' do get :index assert_response :success end it 'shows a cupcake' do get :show, id: cupcakes(:sprinkle) assert_response :success end end
  122. require 'test_helper' class CupcakesHelperTest < ActionView::TestCase def setup @cupcake =

    Cupcake.new name: "Icy McIcerson", image_url: "http://i.imgur.com/mbWH1gM.png" end def test_alt_text image_tag_html = cupcake_image_tag @cupcake assert_match "alt=\"#{@cupcake.name}\"", image_tag_html end def test_image_url image_tag_html = cupcake_image_tag @cupcake assert_match "src=\"#{@cupcake.image_url}\"", image_tag_html end def test_blank_image_url @cupcake.image_url = nil image_tag_html = cupcake_image_tag @cupcake assert_match "src=\"#{Cupcake::DEFAULT_IMAGE_URL}\"", image_tag_html end end test/helpers/cupcakes_helper_test.rb
  123. require 'test_helper' describe CupcakeHelper do let(:cupcake) { Cupcake.new name: "Icy

    McIcerson", image_url: "http://i.imgur.com/mbWH1gM.png" } let(:image_tag_html) { cupcake_image_tag cupcake } it "sets the alt text" do image_tag_html.must_match "alt=\"#{cupcake.name}\"" end it "uses the image_url" do image_tag_html.must_match "src=\"#{cupcake.image_url}\"" end it "uses a default image url if needed" do cupcake.image_url = nil image_tag_html.must_match "src=\"#{Cupcake::DEFAULT_IMAGE_URL}\"" end end test/helpers/cupcakes_helper_test.rb
  124. But Pinkie!

  125. But Pinkie! Can I use nested context blocks?

  126. require "test_helper" describe Pony do let(:twilight_sparkle) { Pony.new name: "Twilight

    Sparkle" } it "knows it's name" do twilight_sparkle.name.must_equal "Twilight Sparkle" end it "knows about friendship" do twilight_sparkle.friendship.must_equal "magic" end end test/models/pony_test.rb
  127. require "test_helper" describe Pony do let(:twilight_sparkle) { Pony.new name: "Twilight

    Sparkle" } it "knows it's name" do twilight_sparkle.name.must_equal "Twilight Sparkle" end it "knows about friendship" do twilight_sparkle.friendship.must_equal "magic" end end test/models/pony_test.rb $ rake test:models Run options: --seed 43295 # Running tests: ... Finished tests in 0.057017s, 52.6159 tests/s, 70.1545 assertions/s. 3 tests, 4 assertions, 0 failures, 0 errors, 0 skips
  128. test/models/pony_test.rb require "test_helper" describe Pony do let(:twilight_sparkle) { Pony.new name:

    "Twilight Sparkle" } it "knows it's name" do twilight_sparkle.name.must_equal "Twilight Sparkle" end context do it "knows about friendship" do twilight_sparkle.friendship.must_equal "magic" end end end
  129. test/models/pony_test.rb require "test_helper" describe Pony do let(:twilight_sparkle) { Pony.new name:

    "Twilight Sparkle" } it "knows it's name" do twilight_sparkle.name.must_equal "Twilight Sparkle" end context do it "knows about friendship" do twilight_sparkle.friendship.must_equal "magic" end end end $ rake test:models rake aborted! undefined method `context' for #<Class:0x007fa4364ea070> ~/pinkie_shop/test/models/pony_test.rb:10:in `block in <top (required)>' ~/pinkie_shop/test/models/pony_test.rb:3:in `<top (required)>' Tasks: TOP => test:models (See full trace by running task with --trace) Run options: --seed 55683 # Running tests: .. Finished tests in 0.057922s, 34.5292 tests/s, 51.7938 assertions/s. 2 tests, 3 assertions, 0 failures, 0 errors, 0 skips
  130. test/models/pony_test.rb require "test_helper" describe Pony do let(:twilight_sparkle) { Pony.new name:

    "Twilight Sparkle" } it "knows it's name" do twilight_sparkle.name.must_equal "Twilight Sparkle" end describe :friendship do it "knows about friendship" do twilight_sparkle.friendship.must_equal "magic" end end end
  131. test/models/pony_test.rb require "test_helper" describe Pony do let(:twilight_sparkle) { Pony.new name:

    "Twilight Sparkle" } it "knows it's name" do twilight_sparkle.name.must_equal "Twilight Sparkle" end describe :friendship do it "knows about friendship" do twilight_sparkle.friendship.must_equal "magic" end end end $ rake test:models Run options: --seed 31855 # Running tests: .. Finished tests in 0.076128s, 26.2715 tests/s, 39.4073 assertions/s. 2 tests, 3 assertions, 0 failures, 0 errors, 0 skips
  132. test/test_helper.rb ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require

    "minitest/spec" class ActiveSupport::TestCase ActiveRecord::Migration.check_pending! # Setup all fixtures in test/fixtures/*.yml for all tests in... # # Note: You'll currently still have to declare fixtures explicitly... # -- they do not yet inherit this setting fixtures :all # Add more helper methods to be used by all tests here... class << self remove_method :describe end if self.respond_to? :describe extend Minitest::Spec::DSL register_spec_type(self) do |desc| desc < ActiveRecord::Base if desc.is_a?(Class) end end
  133. test/test_helper.rb ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require

    "minitest/spec" class ActiveSupport::TestCase ActiveRecord::Migration.check_pending! # Setup all fixtures in test/fixtures/*.yml for all tests in... # # Note: You'll currently still have to declare fixtures explicitly... # -- they do not yet inherit this setting fixtures :all # Add more helper methods to be used by all tests here... class << self remove_method :describe end if self.respond_to? :describe extend Minitest::Spec::DSL register_spec_type(self) do |desc| desc < ActiveRecord::Base if desc.is_a?(Class) end end $ rake test:models Run options: --seed 24 # Running tests: ... Finished tests in 0.054639s, 54.9058 tests/s, 73.2078 assertions/s. 3 tests, 4 assertions, 0 failures, 0 errors, 0 skips
  134. But Pinkie!

  135. But Pinkie! That’s a lot of test_helper config. Can it

    be simpler?
  136. minitest-rails

  137. test/test_helper.rb ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require

    "minitest/spec" class ActiveSupport::TestCase ActiveRecord::Migration.check_pending! # Setup all fixtures in test/fixtures/*.yml for all tests in... # # Note: You'll currently still have to declare fixtures explicitly... # -- they do not yet inherit this setting fixtures :all # Add more helper methods to be used by all tests here... class << self remove_method :describe end if self.respond_to? :describe extend Minitest::Spec::DSL register_spec_type(self) do |desc| desc < ActiveRecord::Base if desc.is_a?(Class) end end
  138. test/test_helper.rb ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require

    "minitest/rails" class ActiveSupport::TestCase ActiveRecord::Migration.check_pending! # Setup all fixtures in test/fixtures/*.yml for all tests in... # # Note: You'll currently still have to declare fixtures explicitly... # -- they do not yet inherit this setting fixtures :all # Add more helper methods to be used by all tests here... end
  139. But Pinkie!

  140. But Pinkie! How do I turn my custom Assertions into

    Expectations?
  141. test/pony_assertions.rb module PonyAssertions def assert_favorite cupcake, pony assert pony.cupcakes.include?(cupcake), "Expected

    #{pony.name} to have favorited #{cupcake.name}" end end class ActiveSupport::TestCase include PonyAssertions end
  142. test/pony_expectations.rb module PonyExpectations # assert_favorite apple_cupcake, apple_jack # apple_jack.must_have_favorited apple_cupcake

    infect_an_assertion :assert_favorite, :must_have_favorited end class Object include PonyExpectations end
  143. test/test_helper.rb ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require

    "minitest/rails" require "pony_assertions" require "pony_expectations" class ActiveSupport::TestCase ActiveRecord::Migration.check_pending! # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting fixtures :all # Add more helper methods to be used by all tests here... end
  144. test/test_helper.rb ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require

    "minitest/rails" require "pony_assertions" require "pony_expectations" class ActiveSupport::TestCase ActiveRecord::Migration.check_pending! # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting fixtures :all # Add more helper methods to be used by all tests here... end
  145. test/models/favorite_test.rb require "test_helper" class FavoriteTest < ActiveSupport::TestCase def test_favorite assert_favorite

    cupcakes(:sprinkle), ponies(:twilight) end end
  146. test/models/favorite_test.rb require "test_helper" describe Favorite do it "allows ponies to

    favorite cupcakes" do ponies(:twilight).must_have_favorited cupcakes(:sprinkle) end end
  147. But Pinkie!

  148. But Pinkie! Can I use describe/it blocks with assertions?

  149. require "test_helper" describe Pony do let(:twilight_sparkle) { Pony.new name: "Twilight

    Sparkle" } it "knows it's name" do assert_equal "Twilight Sparkle", twilight_sparkle.name end it "knows about friendship" do assert_equal "magic", twilight_sparkle.friendship end end test/models/pony_test.rb
  150. require "test_helper" class PonyTest < ActiveSupport::TestCase def twilight_sparkle @twilight_sparkle ||=

    Pony.new name: "Twilight Sparkle" end def test_name twilight_sparkle.name.must_equal "Twilight Sparkle" end def test_friendship twilight_sparkle.friendship.must_equal "magic" end end test/models/pony_test.rb
  151. But Pinkie!

  152. But Pinkie! I want to test my app using Capybara.

    Can I?
  153. minitest-rails-capybara

  154. test/test_helper.rb ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require

    "minitest/rails" require "minitest/rails/capybara" class ActiveSupport::TestCase ActiveRecord::Migration.check_pending! # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting fixtures :all # Add more helper methods to be used by all tests here... end
  155. test/test_helper.rb ENV["RAILS_ENV"] ||= "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require

    "minitest/rails" require "minitest/rails/capybara" class ActiveSupport::TestCase ActiveRecord::Migration.check_pending! # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting fixtures :all # Add more helper methods to be used by all tests here... end
  156. test/features/login_test.rb require "test_helper" class LoginTest < Capybara::Rails::TestCase def setup @pinkie_password

    = "pinkiepie" @pinkie = ponies :pinkie @pinkie.password = @pinkie_password @pinkie.save end end
  157. test/features/login_test.rb require "test_helper" class LoginTest < Capybara::Rails::TestCase def setup @pinkie_password

    = "pinkiepie" @pinkie = ponies :pinkie @pinkie.password = @pinkie_password @pinkie.save end end
  158. test/features/login_test.rb require "test_helper" class LoginTest < Capybara::Rails::TestCase def setup ...

    def test_login_as_pinkie_pie visit root_path assert_have_content page, "login" assert_have_content page, "signup" refute_have_content page, "logout" end end $ rake minitest:features Run options: --seed 65422 # Running tests: . Finished tests in 0.179815s, 5.5613 tests/s, 16.6838 assertions/s. 1 tests, 3 assertions, 0 failures, 0 errors, 0 skips
  159. test/features/login_test.rb require "test_helper" class LoginTest < Capybara::Rails::TestCase def setup ...

    def test_login_as_pinkie_pie visit root_path assert_have_content page, "login" assert_have_content page, "signup" refute_have_content page, "logout" end end $ rake minitest:features Run options: --seed 65422 # Running tests: . Finished tests in 0.179815s, 5.5613 tests/s, 16.6838 assertions/s. 1 tests, 3 assertions, 0 failures, 0 errors, 0 skips $ rake minitest:features Run options: --seed 65422 # Running tests: . Finished tests in 0.179815s, 5.5613 tests/s, 16.6838 assertions/s. 1 tests, 3 assertions, 0 failures, 0 errors, 0 skips
  160. test/features/login_test.rb require "test_helper" class LoginTest < Capybara::Rails::TestCase def setup ...

    def test_login_as_pinkie_pie visit root_path assert_have_content page, "login" assert_have_content page, "signup" refute_have_content page, "logout" end end $ rake minitest:features Run options: --seed 65422 # Running tests: . Finished tests in 0.179815s, 5.5613 tests/s, 16.6838 assertions/s. 1 tests, 3 assertions, 0 failures, 0 errors, 0 skips $ rake minitest:features Run options: --seed 65422 # Running tests: . Finished tests in 0.179815s, 5.5613 tests/s, 16.6838 assertions/s. 1 tests, 3 assertions, 0 failures, 0 errors, 0 skips
  161. test/features/login_test.rb require "test_helper" class LoginTest < Capybara::Rails::TestCase def setup ...

    def test_login_as_pinkie_pie visit root_path assert_have_content page, "login" assert_have_content page, "signup" refute_have_content page, "logout" click_link "login" fill_in "Email", with: @pinkie.email fill_in "Password", with: @pinkie_password click_button "Sign in" assert_have_content page, "logout" assert_have_content page, @pinkie.email refute_have_content page, "login" refute_have_content page, "signup" end end
  162. test/features/login_test.rb require "test_helper" class LoginTest < Capybara::Rails::TestCase def setup ...

    def test_login_as_pinkie_pie visit root_path assert_have_content page, "login" assert_have_content page, "signup" refute_have_content page, "logout" click_link "login" fill_in "Email", with: @pinkie.email fill_in "Password", with: @pinkie_password click_button "Sign in" assert_have_content page, "logout" assert_have_content page, @pinkie.email refute_have_content page, "login" refute_have_content page, "signup" end end $ rake minitest:features Run options: --seed 27176 # Running tests: . Finished tests in 0.318181s, 3.1429 tests/s, 22.0001 assertions/s. 1 tests, 7 assertions, 0 failures, 0 errors, 0 skips
  163. test/features/login_test.rb require "test_helper" class LoginTest < Capybara::Rails::TestCase def setup ...

    end def test_login_as_pinkie_pie ... end def assert_nav_links_logged_in pony page.must_have_content "logout" page.must_have_content pony.email page.wont_have_content "login" page.wont_have_content "signup" end def refute_nav_links_logged_in pony = nil page.must_have_content "login" page.must_have_content "signup" page.wont_have_content "logout" end end
  164. test/features/login_test.rb require "test_helper" class LoginTest < Capybara::Rails::TestCase def setup ...

    end def test_login_as_pinkie_pie visit root_path refute_nav_links_logged_in click_link "login" fill_in "Email", with: @pinkie.email fill_in "Password", with: @pinkie_password click_button "Sign in" assert_nav_links_logged_in @pinkie end def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end
  165. test/features/login_test.rb require "test_helper" class LoginTest < Capybara::Rails::TestCase def setup ...

    end def test_login_as_pinkie_pie visit root_path refute_nav_links_logged_in click_link "login" fill_in "Email", with: @pinkie.email fill_in "Password", with: @pinkie_password click_button "Sign in" assert_nav_links_logged_in @pinkie end def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end $ rake minitest:features Run options: --seed 51819 # Running tests: . Finished tests in 0.285183s, 3.5065 tests/s, 24.5456 assertions/s. 1 tests, 7 assertions, 0 failures, 0 errors, 0 skips
  166. test/features/login_test.rb require "test_helper" class LoginTest < Capybara::Rails::TestCase def setup ...

    end def test_login_as_pinkie_pie visit root_path refute_nav_links_logged_in click_link "login" fill_in "Email", with: @pinkie.email fill_in "Password", with: @pinkie_password click_button "Sign in" assert_nav_links_logged_in @pinkie end def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end $ rake minitest:features Run options: --seed 51819 # Running tests: . Finished tests in 0.285183s, 3.5065 tests/s, 24.5456 assertions/s. 1 tests, 7 assertions, 0 failures, 0 errors, 0 skips
  167. But Pinkie!

  168. But Pinkie! What about Capybara’s DSL? I really like it...

  169. test/features/login_test.rb require "test_helper" class LoginTest < Capybara::Rails::TestCase def setup ...

    def test_login_as_pinkie_pie visit root_path refute_nav_links_logged_in click_link "login" fill_in "Email", with: @pinkie.email fill_in "Password", with: @pinkie_password click_button "Sign in" assert_nav_links_logged_in @pinkie end def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end
  170. test/features/login_test.rb require "test_helper" class LoginTest < Capybara::Rails::TestCase def setup ...

    def test_login_as_pinkie_pie visit root_path refute_nav_links_logged_in click_link "login" fill_in "Email", with: @pinkie.email fill_in "Password", with: @pinkie_password click_button "Sign in" assert_nav_links_logged_in @pinkie end def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end
  171. test/features/login_test.rb require "test_helper" feature "Login Feature" do def setup ...

    def test_login_as_pinkie_pie visit root_path refute_nav_links_logged_in click_link "login" fill_in "Email", with: @pinkie.email fill_in "Password", with: @pinkie_password click_button "Sign in" assert_nav_links_logged_in @pinkie end def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end
  172. test/features/login_test.rb require "test_helper" feature "Login Feature" do def setup ...

    def test_login_as_pinkie_pie visit root_path refute_nav_links_logged_in click_link "login" fill_in "Email", with: @pinkie.email fill_in "Password", with: @pinkie_password click_button "Sign in" assert_nav_links_logged_in @pinkie end def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end
  173. test/features/login_test.rb require "test_helper" feature "Login Feature" do def setup ...

    scenario "logging in as Pinkie Pie" do visit root_path refute_nav_links_logged_in click_link "login" fill_in "Email", with: @pinkie.email fill_in "Password", with: @pinkie_password click_button "Sign in" assert_nav_links_logged_in @pinkie end def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end
  174. test/features/login_test.rb require "test_helper" feature "Login Feature" do def setup @pinkie_password

    = "pinkiepie" @pinkie = ponies :pinkie @pinkie.password = @pinkie_password @pinkie.save end scenario "logging in as Pinkie Pie" do ... def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end
  175. test/features/login_test.rb require "test_helper" feature "Login Feature" do given(:pinkie_password) { "pinkiepie"

    } def setup @pinkie = ponies :pinkie @pinkie.password = pinkie_password @pinkie.save end scenario "logging in as Pinkie Pie" do ... def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end
  176. test/features/login_test.rb require "test_helper" feature "Login Feature" do given(:pinkie_password) { "pinkiepie"

    } given(:pinkie) { p = ponies :pinkie p.password = pinkie_password p.save p } scenario "logging in as Pinkie Pie" do ... def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end
  177. test/features/login_test.rb require "test_helper" feature "Login Feature" do given(:pinkie_password) { "pinkiepie"

    } given(:pinkie) { p = ponies :pinkie ... } scenario "logging in as Pinkie Pie" do visit root_path refute_nav_links_logged_in click_link "login" fill_in "Email", with: pinkie.email fill_in "Password", with: pinkie_password click_button "Sign in" assert_nav_links_logged_in pinkie end def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end
  178. test/features/login_test.rb require "test_helper" feature "Login Feature" do given(:pinkie_password) { "pinkiepie"

    } given(:pinkie) { p = ponies :pinkie ... } scenario "logging in as Pinkie Pie" do visit root_path refute_nav_links_logged_in click_link "login" fill_in "Email", with: pinkie.email fill_in "Password", with: pinkie_password click_button "Sign in" assert_nav_links_logged_in pinkie end def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end $ rake minitest:features Run options: --seed 51819 # Running tests: . Finished tests in 0.285183s, 3.5065 tests/s, 24.5456 assertions/s. 1 tests, 7 assertions, 0 failures, 0 errors, 0 skips
  179. test/features/login_test.rb require "test_helper" feature "Login Feature" do given(:pinkie_password) { "pinkiepie"

    } given(:pinkie) { p = ponies :pinkie ... } scenario "logging in as Pinkie Pie" do visit root_path refute_nav_links_logged_in click_link "login" fill_in "Email", with: pinkie.email fill_in "Password", with: pinkie_password click_button "Sign in" assert_nav_links_logged_in pinkie end def assert_nav_links_logged_in pony ... def refute_nav_links_logged_in pony = nil ... end $ rake minitest:features Run options: --seed 51819 # Running tests: . Finished tests in 0.285183s, 3.5065 tests/s, 24.5456 assertions/s. 1 tests, 7 assertions, 0 failures, 0 errors, 0 skips
  180. But Pinkie!

  181. But Pinkie! What about mocks? Or matchers?

  182. None
  183. None
  184. None
  185. None
  186. I’m sorry

  187. None
  188. Mike Moore @blowmage blowmage.com

  189. Questions/Comments?

  190. Twilight Sparkle Image Credits • Twilight Sparkle is Curious by

    Alixey http://alixey.deviantart.com/art/Twilight-Sparkle-is-Curious-335163906 • Skeptical, annoyed Twilight by MrHavre http://mrhavre.deviantart.com/art/Skeptical-annoyed-Twilight-333256895 • Twilight memories by HankOfficer http://hankofficer.deviantart.com/art/Twilight-memories-316846734 • Twilight Sparkle's Transformation by Sairoch http://sairoch.deviantart.com/art/Twilight-Sparkle-s-Transformation-356096575 • Twilight Sparkle Alicorn Vector by Kamyk962 http://kamyk962.deviantart.com/art/Twilight-Sparkle-Alicorn-Vector-355000137
  191. Pinkie Pie Image Credits •Pinkie Pie by KyssS by KyssS90

    http://kysss90.deviantart.com/art/Pinkie-Pie-by-KyssS-353498032 •Sly Pinkie Pie by Sairoch http://sairoch.deviantart.com/art/Sly-Pinkie-Pie-353454194 •Season 2 Poster Pinkie Pie by VladimirMacHolzraum http://vladimirmacholzraum.deviantart.com/art/Season-2-Poster- Pinkie-Pie-333531305 •Pinkie Pie by CrusierPL http://crusierpl.deviantart.com/art/Pinkie-Pie-279503261
  192. Pinkie Pie Image Credits •Pinkie Glasses by J-Brony http://j-brony.deviantart.com/art/Pinkie-Glasses-264170145 •Extremely

    Surprised Pinkie by IamthegreatLyra http://iamthegreatlyra.deviantart.com/art/Extremely-Surprised- Pinkie-279356130 •Haters Gonna' Hate by binaryNinj4 http://binaryninj4.deviantart.com/art/Haters-Gonna-Hate-201850847 •Pinkie Pie Overwrought by Sairoch http://sairoch.deviantart.com/art/Pinkie-Pie-Overwrought-363028991
  193. None