您好我正在研究Daniel Kehoe的Rspec Tutorial。在我创建文件spec / features / visitor / home_page_spec.rb之前,一切都很顺利。当我在其中放入以下测试代码时
# Feature: Home Page
# As a visitor
# I want to visit a home page
# So I can learn more about the website
feature 'Home Page' do
# Scenario: Visit the Home Page
# Given I am a visitor
# When I visit the home page
# Then I should see "Welcome"
scenario 'Visit the Home Page' do
visit root_path
expect(page).to have_content 'Welcome'
end
end
从终端运行rspec spec / features / visitor / home_page_spec.rb,我收到以下错误。我知道方法没有定义,但丹尼尔的教程只是告诉你把代码放在上面的文件夹中。猜猜我错过了什么。谢谢
rails-bootstrap/spec/features/visitor/home_page_spec.rb:7:in `<top (required)>':
undefined method `feature' for main:Object (NoMethodError)
答案 0 :(得分:2)
项目目录中 .rspec 文件中的内容是什么?你应该:
--color
--format documentation
--require spec_helper
--require rails_helper
如果 .rspec 文件设置正确,您的spec文件中不需要额外的require
个语句。
答案 1 :(得分:0)
我 rake test 运行的唯一方法是将以下要求添加到 test / integration / home_page_test.rb
require 'minitest/rails/capybara'
这一行已经在 test / test_helper.rb 中了,所以我不确定为什么它不能捡起来。我还尝试使用Daniel建议的选项添加 .rspec 文件。如果没有其他工作,请尝试。