【问题标题】:Rspec 3.0.0 Update Ruby on Rails falling testsRspec 3.0.0 更新 Ruby on Rails 跌落测试
【发布时间】:2014-05-19 16:59:25
【问题描述】:

我使用了gem 'rspec-rails'(所有测试都通过了),我将其更新为gem 'rspec-rails', '~> 3.0.0.beta',现在几乎所有测试都失败了,例如:

rspec ./spec/features/static_pages_spec.rb:60 # languages index

我的测试看起来像:

require 'spec_helper'
describe "languages" do
  subject { page }

  describe "index" do
    before { visit root_path }

    it { should have_title('EduWords') }
    it { should have_content("Toggle navigation EduWords Home Sign up Log in Authors Back to Top EduWords © MiDaS Project 2014") }

  end
end

我做错了什么?

config/routes

Eduwords::Application.routes.draw do
  get "authors/index"
  get "mainpage/index"
  resources :tags

  resources :languages

  resources :words

  resources :tests

  resources :users

  get "sessions/new"
  get "users/new"

  get "download", to: "words#download", as: 'download'

  get "log_out" => "sessions#destroy", :as => "log_out"
  get "log_in" => "sessions#new", :as => "log_in"
  get "sign_up" => "users#new", :as => "sign_up"
  root :to => "mainpage#index"
  resources :users
  resources :sessions
end

【问题讨论】:

  • 能否添加测试失败的输出?
  • 24) LanguagesController 路由语言路由到语言#new 失败/错误:expect(:get => "/languages/new").to route_to("languages#new") NoMethodError: undefined method @ 987654327@block (3 个级别) in '
  • 这不是您在答案中输入的测试的失败规范。
  • 抱歉:34) 语言索引失败/错误:在 { 访问 root_path } 之前 NameError:未定义的局部变量或方法 root_path' for #<RSpec::ExampleGroups::Languages_2::Index:0x00000002cd5d78> # ./spec/features/static_pages_spec.rb:58:in block(3 级)在 '
  • 您的config/routes.rb 中有什么内容?

标签: ruby-on-rails ruby rspec gem


【解决方案1】:

听起来 RSpec 没有找到你的 route_helper 方法(例如root_path)。这是该问题的答案:

https://stackoverflow.com/a/9476576/2231608

如果您将以下内容放入 rspec_helper.rb 中,命名路由应该可以工作:

Rspec.configure do |config|
  config.include Rails.application.routes.url_helpers
  ...
end

你是这样设置的吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 2016-01-25
    • 2020-09-20
    相关资源
    最近更新 更多