水豚的自述文件(見Using Capybara with MiniTest::Spec)說我可以做到這一點,如果我正確地包括模塊,但它沒有給出任何說明性示例如何......我試過包括這樣的模塊:水豚驗收DSL與MiniTest ::規格?
class MiniTest::Spec
include Capybara::DSL
end
...無濟於事。我一直得到這個錯誤:
<main>': undefined method
feature' for main:Object (NoMethodError)
我怎樣才能得到它的工作,因爲它寫在註釋掉的代碼?
規格/接受/ API/reward_terms_spec.rb:
require "#{Dir.pwd}/spec/acceptance/acceptance_helper"
# this syntax works...
describe 'reward terms acceptance test' do
include Capybara::DSL
describe '#index' do
specify {
visit '/reward_terms'
# ...
}
end
end
# this syntax doesn't work...
# feature 'RewardTerms', %q{
# In order to get all reward terms available to me
# As an API client
# I want to list all active RewardTerms
# } do
# background do
# set_api_headers
# end
# scenario 'RewardTerm index' do
# visit '/reward_terms'
# ...
# end
# end
規格/接受/ acceptance_helper.rb:
ENV["RAILS_ENV"] = "test"
require "#{Dir.pwd}/config/environment"
require 'minitest/autorun'
require 'capybara/rails'
def set_api_headers(device_id = 'abcd1234')
header 'Accept', 'application/json'
header 'X-Device-Id', device_id
end
是啊,我看到了帖子,但只允許你使用水豚的匹配,而不是BDD DSL進行驗收測試,這是什麼我之後... – neezer
在[link](https://github.com/jnicklas/capybara)上,關於Capybara DSL的部分包含在「使用RSpec的Capybara」一節中,它說「最後,Capybara也來了用內置的DSL創建描述性驗收測試:「。然而,在展示DSL實際運行後,它說:「'feature'實際上只是'describe ...,:type =>:request'的別名,'background'是'before'和'scenario'的別名爲'它'。「所以如果你想在MiniTest中使用它,因爲它是RSpec唯一的功能,所以你運氣不好,但是你可能試着定義你自己的別名 – Patru
鏈接的博客帖子已從Posterous中刪除,但是在這裏是在Internet Archive:http://web.archive.org/web/20130314201201/http://code-ningja.posterous.com/73460416 –