gpt4 book ai didi

ruby-on-rails - 使用工厂女孩和 capybara 将日期输入到表单中

转载 作者:行者123 更新时间:2023-12-04 06:34:09 24 4
gpt4 key购买 nike

我有一个 Group 模型,我正在使用带有 Capybara 的请求规范进行测试,并使用 Factory Girl 生成数据

在我的 groups.rb 工厂中...

FactoryGirl.define do
factory :group do
sequence :name do |n|
"Group#{n}"
end
expiry Date.today + 2.weeks
end
end

并在我的 groups_spec.rb 中使用它...
describe "Groups" do
describe "GET /groups" do
it "an admin user can create a new group" do
user = Factory.create(:user, :is_admin => true )
group = Factory.build(:group)

visit root_url
fill_in "Email", :with => user.email
fill_in "Password", :with => user.password
click_button "Login"
click_link "Groups"
click_link "New Group"
fill_in "Name", :with => group.name
# need to change the below to use the Factory eg select Date.new(group.expiry)
select "2014", :from => "group_expiry_1i"
select "June", :from => "group_expiry_2i"
select "1", :from => "group_expiry_3i"
click_button "Create Group"
page.should have_content("Group was successfully created.")
page.should have_content(group.name)
end
end
end

因此,您会发现这不是进行测试的好方法,因为我没有使用工厂生成的到期时间。有谁知道如何在表格中正确输入到期日期?

最佳答案

这只是袖口上的,没有在 Capybara 中进行测试,但我会尝试:

select group.expiry.year.to_s, :from => "group_expiry_1i"
select Date::MONTHNAMES[group.expiry.month], :from => "group_expiry_2i"
select group.expiry.date.to_s, :from => "group_expiry_3i"

只要这些值确实存在于下拉列表中,它就应该正确选择它们。

关于ruby-on-rails - 使用工厂女孩和 capybara 将日期输入到表单中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9387840/

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