Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Tutorial 5.3.0 TDD Error: "undefined method 'visit'"
    primarykey
    data
    text
    <p>Following the Hartl Tutorial online and can't seem to find a solution to Chapter 5 section 3.0. At this point of the tutorial, I seems that I am supposed to make my rspec code more concise by defining a full_title in "spec/support/utilities.rb" then editing the "spec/requests/static_pages_spec.rb" file. </p> <p>Here is my "spec/support/utilities.rb":</p> <pre><code>def full_title(page_title) base_title = "Ruby on Rails Tutorial Sample App" if page_title.empty? base_title else "#{base_title} | #{page_title}" end end </code></pre> <p>and my "spec/requests/static_pages_spec.rb":</p> <pre><code>require 'spec_helper' describe "Static pages" do subject { page } describe "Home page" do before { visit root_path } it { should have_content('Sample App') } it { should have_title(full_title('')) } it { should_not have_title('| Home') } end describe "Help page" do before { vist root_path } it { should have_content('Help') } it { should have_title(full_title('Help')) } end describe "About page" do before { visit root_path} it { should have_content('About') } it { should have_title(full_title('About')) } end describe "Contact page" do before { visit contact_path } it { should have_content('Contact') } it { should have_title(full_title('Contact')) } end end </code></pre> <p>and my "spec_helper.rb": </p> <pre><code>require 'rubygems' require 'spork' Spork.prefork do ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' require 'capybara/rspec' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} # Checks for pending migrations before tests are run. # If you are not using ActiveRecord, you can remove this line. ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) RSpec.configure do |config| # ## Mock Framework # # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: # # config.mock_with :mocha # config.mock_with :flexmock # config.mock_with :rr # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. config.use_transactional_fixtures = true # If true, the base class of anonymous controllers will be inferred # automatically. This will be the default behavior in future versions of # rspec-rails. config.infer_base_class_for_anonymous_controllers = false # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. # --seed 1234 config.order = "random" config.include Capybara::DSL end end Spork.each_run do # This code will be run each time you run your specs. end </code></pre> <p>When I run: </p> <pre><code>$ bundle exec rspec spec/requests/static_pages_spec.rb </code></pre> <p>I get: </p> <pre><code>Failures: 1) Static pages About page Failure/Error: it { should have_title(full_title('About')) } expected #has_title?("Ruby on Rails Tutorial Sample App | About") to return true, got false # ./spec/requests/static_pages_spec.rb:26:in `block (3 levels) in &lt;top (required)&gt;' 2) Static pages Help page Failure/Error: before { vist root_path } NoMethodError: undefined method `vist' for #&lt;RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007fe53b33f338&gt; # ./spec/requests/static_pages_spec.rb:16:in `block (3 levels) in &lt;top (required)&gt;' 3) Static pages Help page Failure/Error: before { vist root_path } NoMethodError: undefined method `vist' for #&lt;RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007fe53b44d8b0&gt; # ./spec/requests/static_pages_spec.rb:16:in `block (3 levels) in &lt;top (required)&gt;' Finished in 0.28441 seconds 9 examples, 3 failures Failed examples: rspec ./spec/requests/static_pages_spec.rb:26 # Static pages About page rspec ./spec/requests/static_pages_spec.rb:18 # Static pages Help page rspec ./spec/requests/static_pages_spec.rb:19 # Static pages Help page </code></pre> <p>I've seen on other posts that this error may be due to a lack of "Capybara" because "visit" is a Capybara method. I checked my Gem file and it shows Capybara: </p> <pre><code>source 'https://rubygems.org' ruby '2.0.0' #ruby-gemset=railstutorial_rails_4_0 gem 'rails', '4.0.0' gem 'bootstrap-sass', '2.3.2.0' gem 'bcrypt-ruby', '3.0.1' gem 'faker', '1.1.2' gem 'will_paginate', '3.0.4' gem 'bootstrap-will_paginate', '0.0.9' group :development, :test do gem 'sqlite3', '1.3.7' gem 'rspec-rails', '2.13.1' # The following optional lines are part of the advanced setup. gem 'guard-rspec', '2.5.0' gem 'spork-rails', github: 'sporkrb/spork-rails' gem 'guard-spork', '1.5.0' gem 'childprocess', '0.3.6' end group :test do gem 'selenium-webdriver', '2.0.0' gem 'capybara', '2.1.0' gem 'factory_girl_rails', '4.2.0' gem 'cucumber-rails', '1.3.0', :require =&gt; false gem 'database_cleaner', github: 'bmabey/database_cleaner' # Uncomment this line on OS X. # gem 'growl', '1.0.3' # Uncomment these lines on Linux. # gem 'libnotify', '0.8.0' # Uncomment these lines on Windows. # gem 'rb-notifu', '0.0.4' # gem 'win32console', '1.3.2' end gem 'sass-rails', '4.0.0' gem 'uglifier', '2.1.1' gem 'coffee-rails', '4.0.0' gem 'jquery-rails', '2.2.1' gem 'turbolinks', '1.1.1' gem 'jbuilder', '1.0.2' group :doc do gem 'sdoc', '0.3.20', require: false end group :production do gem 'pg', '0.15.1' gem 'rails_12factor', '0.0.2' end </code></pre> <p>I'm not sure what is needed to make <code>visit</code> a valid method for the test?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload