I have a Group model that I am testing using Request specs with Capybara and generating the 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 as I’m not using the factory generated expiry. Does anyone know how to input the expiry date into the form properly?
This is just off the cuff without testing in Capybara, but I’d try:
As long as those values actually exist in the dropdown it should select them correctly.