gpt4 book ai didi

ruby-on-rails-3 - Capybara Acceptance DSL 与 MiniTest::Spec?

转载 作者:行者123 更新时间:2023-12-03 00:44:03 27 4
gpt4 key购买 nike

Capybara 的自述文件(参见 Using Capybara with MiniTest::Spec )说,如果我正确包含该模块,我可以做到这一点,但它没有给出任何说明性示例...我尝试过包含这样的模块:

class MiniTest::Spec
include Capybara::DSL
end

...没有用。我不断收到此错误:

<main>': undefined methodfeature' for main:Object (NoMethodError)

如何让它按照注释掉的代码中编写的那样工作?

<小时/>

spec/acceptance/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

spec/acceptance/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

最佳答案

this post中有一个很好的描述了解如何使 MinitTest::Spec 与 capybara 一起运行。在那里,他基本上将 Capybara::DSL 包含到所有规范的基类中,如下所示

class RequestSpec < MiniTest::Spec
include Rails.application.routes.url_helpers
include Capybara::DSL
end

这在我们的设置中工作得相当好,但当然它不会重新打开 MiniTest::Spec。

关于ruby-on-rails-3 - Capybara Acceptance DSL 与 MiniTest::Spec?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8146787/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com