【问题标题】:Michael Hartl's RoR Tutorial chapter 3 rails generate integration_test does nothing [closed]Michael Hartl 的 RoR 教程第 3 章 rails generate integration_test 什么都不做[关闭]
【发布时间】:2012-05-19 07:51:52
【问题描述】:

我是 Ruby on Rails 的新手,我正在关注 Michael Hartl 的 Ruby on rails 教程。我在测试驱动开发的第 3 章。当我运行命令时

rails 生成 integration_test static_pages

它什么都不做。没有错误,也没有创建规范文件。我已经使用 railsinstaller 安装了 rails。

接下来要做什么?

【问题讨论】:

  • 这是/not/“过于本地化”!

标签: ruby-on-rails railstutorial.org


【解决方案1】:

这是一个简单的问题。将 rspec-rails 放入 gemfile 的开发和测试组中:

group :development, :test do
  gem 'rspec-rails'
end

然后捆绑,您将被设置。当您运行 rails g integration_test 时,它现在将生成测试文件。原因是 rspec-generators 仅在 gem 也在开发组(而不仅仅是测试组)时才会暴露。

【讨论】:

  • 这应该是正确的答案。选择的答案只是规避问题。
  • 这对我也有用。
  • 为我工作,在我的 Gemfile 中发现了一个错字。谢谢!
【解决方案2】:

我不确定它为什么不为您生成文件。当我尝试它时,它起作用了。

只生成一个文件:

require 'test_helper'

class StaticPagesTest < ActionDispatch::IntegrationTest
  # test "the truth" do
  #   assert true
  # end
end

进入test/integration/static_pages_test.rb

【讨论】:

  • 我可以手动添加这个文件并继续吗?
  • 是的。这是唯一生成的文件,没有其他文件被更改。
  • 下面的 Brian Dear 给出了正确的修复方法,将 gem 'rspec-rails' 添加到 development (或者在我的情况下,修复拼写 development 时的拼写错误)。
【解决方案3】:

不知道为什么你不会得到错误。我必须使用

bundle exec rails generate integration_test static_pages

让它工作。

【讨论】:

    【解决方案4】:

    我有同样的问题(即没有错误并且没有创建规范文件)并且 EricM 的解决方案对我不起作用。我在 spec/requests/static_pages_spec.rb 中手动创建了以下文件,它似乎有效(我必须在 spec 中创建 requests 目录):

    require 'spec_helper'
    
    describe "Static pages" do
    
      describe "Home page" do
    
        it "should have the content 'Sample App'" do
          visit '/static_pages/home'
          page.should have_content('Sample App')
        end
      end
    end
    

    这与本书清单 3.9 中使用的代码相同:http://ruby.railstutorial.org/chapters/static-pages#sec:TDD

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多