Enter the date into the form using factory girls and capybara

I have a group model that I am testing using Request specifications with Capybara and generating data using Factory Girl

In my groups .rb factory ...

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

And use this in my 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 

So you see that this is not a good way to do the test, since I do not use the expiration of the Factory. Does anyone know how to correctly enter an expiration date in a form?

+4
source share
2 answers

This is just from the cuff without testing in Capybara, but I would try:

 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" 

As long as these values ​​do exist in the drop-down menu, they must choose them correctly.

+3
source

You can also use select_date:

select_date ('31 / 12/2014 ',: from =>' Expiry ')

+3
source

Source: https://habr.com/ru/post/1397705/


All Articles