Skip to content

Instantly share code, notes, and snippets.

@neilvcarvalho
Last active August 22, 2022 21:47
Show Gist options
  • Save neilvcarvalho/8111848fab4cb833345f7f2f9fc634de to your computer and use it in GitHub Desktop.
Save neilvcarvalho/8111848fab4cb833345f7f2f9fc634de to your computer and use it in GitHub Desktop.

Update notes for the book Testing Rails:

Chapter 2, page 23:

After defining the LinksController class, the book mentions:

Failure/Error: visit root_path
NoMethodError:
  undefined method `action' for LinksController:Class

While Rails 7.0 returns:

Failure/Error: visit root_path

NoMethodError:
  undefined method `action_encoding_template' for LinksController:Class

After adding ApplicationController and creating the index action, the new output is:

Failure/Error: visit root_path

ActionController::MissingExactTemplate:
  LinksController#index is missing a template for request formats: text/html

Chapter 2, page 29

FactoryBot examples use the old syntax, without braces. For example:

# spec/factories.rb
FactoryGirl.define do
  factory :link do
    title "Testing Rails"
    url "http://testingrailsbook.com"
   end
end

# In your test
link = create(:link)

# Or override the title
link = create(:link, title: "TDD isn't Dead!")

Should be:

# spec/factories.rb
FactoryBot.define do
  factory :link do
    title { "Testing Rails" }
    url { "http://testingrailsbook.com" }
   end
end

# In your test
link = FactoryBot.create(:link)

# Or override the title
link = FactoryBot.create(:link, title: "TDD isn't Dead!")

Chapter 2, page 30

Commented out line now reads:

Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }

Commit https://github.com/thoughtbot/testing-rails/commit/10eb83b613bbaf46db7737acdd71ead7052f569a skipped - Not needed, it is already set by default.

Commit https://github.com/thoughtbot/testing-rails/commit/384a7cc1b99aa5f0e737d3432e58b7e52ca0f522 skipped - it's different in newer Rails versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment