当我尝试运行Wayne Ye的Instant Cucumber BDD How-to给我的一个例子时,我不断收到错误消息undefined method 'visit' (NoMethodError)
。我安装了很多宝石,我想我已经在我的项目文件夹上运行了所有必要的命令。
我安装的设置说明是:
gem install selenium-cucumber
gem install bundler
gem install cucumber-rails
gem install launchy
gem install database_cleaner
gem install factory_girl_rails
gem install webmock
gem install pickle
gem install spork-rails
gem install nokogiri
gem install ffi
gem install capybara
chdir C:\DevKit
ruby dk.rb init
ruby dk.rb install
gem install json
gem install sqlite3
<project folder>cucumber --init
<project folder>bundler init
<project folder>bundler install
我试图运行的例子来自本书,看起来像这样。
Amazon.features
Feature: Shopping in Amazon
As an internet user
I want to search stuff on Amazon
So that I can choose and buy items I like
@javascript
Scenario: Search for baseball gloves
Given I am on Amazon homepage
When I enter "baseball glove" in the search box
And I click "Go" button
Then I should see a list of results related with Baseball Gloves
step_definitions / amazon_search_steps.rb
Given /^I am on Amazon homepage$/ do
visit "http://www.amazon.com"
end
When /^I enter "(.*?)" in the search box$/ do |keywords|
fill_in "Search", :with => keywords
end
When /^I click "Go" button$/ do
click_button "Go"
end
Then /^I should see a list of results related with Baseball Gloves/ do
page.should have_content("#centerBelow")
end
运行时,我收到以下错误消息。
在线查看,解决方案似乎是将以下行添加到我的spec_helper.rb
文件中,但我不知道哪一行,而且我尝试过的都没有。
config.include Capybara::DSL
编辑:按照我的env.rb文件要求。
完整路径为C:\ Ruby22-x64 \ lib \ ruby \ gems \ 2.2.0 \ gems \ cucumber-rails-1.4.3 \ features \ support \ env.rb
$:.unshift(File.dirname(__FILE__) + '/../../lib')
require 'rubygems'
require 'bundler/setup'
require 'rspec/expectations'
require 'aruba/cucumber'
if(ENV['ARUBA_REPORT_DIR'])
# Override reporting behaviour so we don't document all files, only the ones
# that have been created after @aruba_report_start (a Time object). This is
# given a value after the Rails app is generated (see cucumber_rails_steps.rb)
module Aruba
module Reporting
def children(dir)
children = Dir["#{dir}/*"].sort
# include
children = children.select do |child|
File.directory?(child) ||
(@aruba_report_start && File.stat(child).mtime > @aruba_report_start)
end
# exclude
children = children.reject do |child|
child =~ /Gemfile/ ||
child =~ /\.log$/
end
children
end
end
end
end