RailsTutorial.org Learning Rails 5.3.4 Layout link tests

While following the tutorial 5.3.4 Layout Link Tests failed.
This is the test ran:
'$ rails generate integration_test site_layout'.
This is the error received:
'/usr/local/rvm/gems/ruby-2.2.1/gems/fog-1.23.0/lib/fog/rackspace/mock_data.rb:42: warning: duplicated key at line 80 ignored: "name" /home/ubuntu/workspace/db/schema.rb doesn't exist yet. Run rake db:migrate to create it, then try again. If you do not intend to use a database, you should instead alter /home/ubuntu/workspace/config/application.rb to limit the frameworks that will be loaded. Started

FAIL["test_layout_links", SiteLayoutTest, 2015-05-10 20:31:00 +0000] test_layout_links#SiteLayoutTest (1431289860.34s) Expected exactly 2 elements matching "a[href="/"]", found 0.. Expected: 2 Actual: 0 test/integration/site_layout_test.rb:8:in `block in '

1/1: [====================================================================================================================] 100% Time: 00:00:00, Time: 00:00:00

Finished in 0.53147s 1 tests, 2 assertions, 1 failures, 0 errors, 0 skips'

This is the file changed prior to running the test and receiving the error:
test/integration/site_layout_test.rb

Below are the contents of the file:
require 'test_helper'

class SiteLayoutTest < ActionDispatch::IntegrationTest test "layout links" do get root_path assert_template 'static_pages/home' assert_select "a[href=?]", root_path, count: 2 assert_select "a[href=?]", help_path assert_select "a[href=?]", about_path assert_select "a[href=?]", contact_path # test "the truth" do # assert true end end What am I doing wrong? Where's my mistake? Please help.

1 thought on “RailsTutorial.org Learning Rails 5.3.4 Layout link tests”

  1. the page at root_path (static_pages/home) is missing 2 links to the root_path, hence the test failure message “Expected exactly 2 elements matching “a[href=”/”]”, found 0.. Expected: 2 Actual: 0 “. The ‘SAMPLE_APP’ text (on the top left) and ‘Home’ (top right) need to have links to the root_path. This is easily remedied by the updating the relevant 2 lines of code in the _header.html.erb to

    1) <%= link_to "sample app", root_path, id: "logo" %>
    and
    2)

  2. <%= link_to "Home", root_path %>
  3. the _header.html.erb should look something like this :

    Reply

Leave a Comment