未定义的局部变量或方法"root_path"(Rspec Spork Guard) [英] undefined local variable or method `root_path' (Rspec Spork Guard)

查看:114
本文介绍了未定义的局部变量或方法"root_path"(Rspec Spork Guard)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个新手问题:-)

I have a newbie question :-)

我正在创建"一个应用程序,并且使用M. Hartl的教程来做到这一点.但是自从我决定更改route.rb以来,我遇到了一些问题. 我知道问题已经发布,但是答案对我来说不起作用,所以我认为我应该再问一个问题...

I'm "creating" an app, and I use M. Hartl's Tutorial to do so. But I have some problems since I decided to change my routes.rb. I know the question has already been posted, but the answer doesn't work for me, so I supposed I should ask a new one...

以下是代码:

Here are the codes :

  root to: 'static_pages#home'
  match '/help', to: 'static_pages#help'
  match '/contact', to: 'static_pages#contact'
  match '/about', to: 'static_pages#about'

spec/requests/static_pages.rb

require 'spec_helper'

describe "Static pages" do

  let(:base_title) { "Vidons" }

  describe "Home page" do
    visit root_path
    it "should have the h1 'Vidons'" do
      page.should have_selector('h1', :text => 'Vidons')
    end
    it "should have the base title" do
      page.should have_selector('title', :text => "#{base_title}")
    end
  end

  describe "Help page" do
    visit help_path
    it "should have the h1 'Aide'" do
      page.should have_selector('h1', :text => 'Aide')
    end
    it "should have the title 'Aide'" do
      page.should have_selector('title', :text => "#{base_title} | Aide")
    end
  end

  describe "About page" do
    visit about_path
    it "should have the h1 'A propos'" do
      page.should have_selector('h1', :text => 'A propos')
    end
    it "should have the title 'A propos'" do
      page.should have_selector('title', :text => "#{base_title} | A propos")
    end
  end

  describe "Contact page" do
    visit contact_path
    it "should have the h1 'Contact'" do
      page.should have_selector('h1', :text => 'Contact')
    end
    it "should have the title 'Contact'" do
      page.should have_selector('title', :text => "#{base_title} | Contact")
    end
  end
end

spec/spec_helper.rb

(我删除了Rspec.configure块之一,并将其​​保留在spork prerun块中)

spec/spec_helper.rb

(I removed one of the Rspec.configure block, and I kept the one that's inside the spork prerun block )

require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'

Spork.prefork do
  # Loading more in this block will cause your tests to run faster. However,
  # if you change any configuration or code from libraries loaded here, you'll
  # need to restart spork for it take effect.
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'

  # 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}

  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
    config.mock_with :rspec

    # 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
  end
end

Spork.each_run do
  # This code will be run each time you run your specs.

end

这是rspec-guard的响应:

And here is the response of rspec-guard :

10:07:46-信息-弃用警告:: version选项已弃用.现在仅支持RSpec 2.

10:07:46 - INFO - DEPRECATION WARNING: The :version option is deprecated. Only RSpec 2 is now supported.

10:07:46-信息-Guard使用Libnotify发送通知.

10:07:46 - INFO - Guard uses Libnotify to send notifications.

10:07:46-信息-Guard使用TerminalTitle发送通知.

10:07:46 - INFO - Guard uses TerminalTitle to send notifications.

10:07:46-信息-为RSpec启动Spork

10:07:46 - INFO - Starting Spork for RSpec

使用RSpec

预加载Rails环境

正在加载Spork.prefork块...

Loading Spork.prefork block...

Rack :: File headers参数在Rack 1.5之后替换了cache_control.

Rack::File headers parameter replaces cache_control after Rack 1.5.

Spork已准备就绪,可以在8989上收听!

Spork is ready and listening on 8989!

10:07:53-信息-RSpec的Spork服务器已成功启动

10:07:53 - INFO - Spork server for RSpec successfully started

10:07:53-信息-Guard :: RSpec正在运行

10:07:53 - INFO - Guard::RSpec is running

10:07:53-信息-运行所有规格

10:07:53 - INFO - Running all specs

使用args ["--drb",-f","progress",-r","/home/flokate/.rvm/gems/ruby​​-1.9.3-p286/gems/guard"运行测试-rspec-2.4.0/lib/guard/rspec/formatter.rb",-f","Guard :: RSpec :: Formatter",-failure-exit-code","2","spec" ] ...

Running tests with args ["--drb", "-f", "progress", "-r", "/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/guard-rspec-2.4.0/lib/guard/rspec/formatter.rb", "-f", "Guard::RSpec::Formatter", "--failure-exit-code", "2", "spec"]...

遇到异常:#>

回溯:

/home/flokate/Rubyrails/vidons/spec/requests/static_pages_spec.rb:8:在'

/home/flokate/Rubyrails/vidons/spec/requests/static_pages_spec.rb:8:in `block (2 levels) in '

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:在'module_eval'中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `module_eval'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:在子类"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `subclass'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:230:位于描述"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:230:in `describe'

/home/flokate/Rubyrails/vidons/spec/requests/static_pages_spec.rb:7:in'block in'

/home/flokate/Rubyrails/vidons/spec/requests/static_pages_spec.rb:7:in `block in '

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:在'module_eval'中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `module_eval'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:在子类"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:244:in `subclass'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:230:位于描述"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/example_group.rb:230:in `describe'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/dsl.rb:18:在描述"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/dsl.rb:18:in `describe'

/home/flokate/Rubyrails/vidons/spec/requests/static_pages_spec.rb:3:in''

/home/flokate/Rubyrails/vidons/spec/requests/static_pages_spec.rb:3:in `'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:在'load'中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:in `load'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:在加载时阻止"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:in `block in load'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:在"load_dependency"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in `load_dependency'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:在'load'中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:in `load'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in`load_spec_files中的块'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `block in load_spec_files'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:在每个"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `each'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:在"load_spec_files"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `load_spec_files'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/command_line.rb:22:在运行"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.12.2/lib/rspec/core/command_line.rb:22:in `run'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/test_framework/rspec.rb:11:在运行测试"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/test_framework/rspec.rb:11:in `run_tests'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:13:在运行中阻止"

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:13:in `block in run'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/forker.rb:21:在初始化中的块"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/forker.rb:21:in `block in initialize'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/forker.rb:18:在"fork"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/forker.rb:18:in `fork'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/forker.rb:18:在初始化"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/forker.rb:18:in `initialize'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:在新"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `new'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:在运行"中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/run_strategy/forking.rb:9:in `run'

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/server.rb:48:在`run'中

/home/flokate/.rvm/gems/ruby-1.9.3-p286/gems/spork-0.9.2/lib/spork/server.rb:48:in `run'

/home/flokate/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/drb/drb.rb:1548:in`perform_without_block'

/home/flokate/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/drb/drb.rb:1548:in `perform_without_block'

/home/flokate/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/drb/drb.rb:1508:执行"

/home/flokate/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/drb/drb.rb:1508:in `perform'

/home/flokate/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/drb/drb.rb:1586:在`main_loop'中的块(2级)中

/home/flokate/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/drb/drb.rb:1586:in `block (2 levels) in main_loop'

/home/flokate/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/drb/drb.rb:1582:in'loop'

/home/flokate/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/drb/drb.rb:1582:in `loop'

/home/flokate/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/drb/drb.rb:1582:在`main_loop中的块中

/home/flokate/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/drb/drb.rb:1582:in `block in main_loop'

完成.

由于DEPRECATION WARNING,我查看了我的Gemfile,并删除了版本号,以便使用我感兴趣的最后一个宝石:

Because of the DEPRECATION WARNING, I looked into my Gemfile, and removed the version's number, in order to use the last gems I'm interested to :

group :development, :test do
  gem 'sqlite3', '1.3.5'
  gem 'rspec-rails'
  gem 'guard-rspec'
  gem 'guard-spork'
  gem 'spork'
end

哪个给我:

Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Using rake (10.0.3) 
Using i18n (0.6.1) 
Using multi_json (1.6.0) 
Using activesupport (3.2.12) 
Using builder (3.0.4) 
Using activemodel (3.2.12) 
Using erubis (2.7.0) 
Using journey (1.0.4) 
Using rack (1.4.5) 
Using rack-cache (1.2) 
Using rack-test (0.6.2) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.2.2) 
Using actionpack (3.2.12) 
Using mime-types (1.21) 
Using polyglot (0.3.3) 
Using treetop (1.4.12) 
Using mail (2.4.4) 
Using actionmailer (3.2.12) 
Using arel (3.0.2) 
Using tzinfo (0.3.35) 
Using activerecord (3.2.12) 
Using activeresource (3.2.12) 
Using annotate (2.5.0) 
Using bcrypt-ruby (3.0.1) 
Using bootstrap-sass (2.1.0.0) 
Using bundler (1.2.3) 
Using nokogiri (1.5.6) 
Using ffi (1.3.1) 
Using childprocess (0.3.8) 
Using rubyzip (0.9.9) 
Using websocket (1.0.7) 
Using selenium-webdriver (2.29.0) 
Using xpath (0.1.4) 
Using capybara (1.1.2) 
Using coderay (1.0.8) 
Using coffee-script-source (1.4.0) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using rack-ssl (1.3.3) 
Using json (1.7.7) 
Using rdoc (3.12.1) 
Using thor (0.17.0) 
Using railties (3.2.12) 
Using coffee-rails (3.2.2) 
Using diff-lcs (1.1.3) 
Using factory_girl (4.1.0) 
Using factory_girl_rails (4.1.0) 
Using listen (0.7.2) 
Using lumberjack (1.0.2) 
Using method_source (0.8.1) 
Using slop (3.4.3) 
Using pry (0.9.12) 
Using terminal-table (1.4.5) 
Using guard (1.6.2) 
Using rspec-core (2.12.2) 
Using rspec-expectations (2.12.1) 
Using rspec-mocks (2.12.2) 
Using rspec (2.12.0) 
Using guard-rspec (2.4.0) 
Using spork (0.9.2) 
Using guard-spork (1.4.2) 
Using jquery-rails (2.0.2) 
Using libnotify (0.5.9) 
Using rails (3.2.12) 
Using rb-inotify (0.8.8) 
Using rspec-rails (2.12.2) 
Using sass (3.2.5) 
Using sass-rails (3.2.5) 
Using sqlite3 (1.3.5) 
Using uglifier (1.2.3) 
Your bundle is updated! Use `bundle show [gemname]` to see where a bundled gem is installed.

它并没有改变任何东西... 我目前还不太了解,但我希望你们中的一个能给我带来曙光;-)

And it didn't change anything... I don't understand much at this time, but I hope one of you will bring me the light ;-)

推荐答案

您只需要在before块内visit root_path:before { visit root_path }

You just have to visit root_path inside a before block: before { visit root_path }

这篇关于未定义的局部变量或方法"root_path"(Rspec Spork Guard)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆