0

I have a dropdown box that is populated using data from the database (via Angular).

I am trying to test it with Capybara and Poltergeist using:

        select('San Francisco', from: "user_region")

As the test database starts with a clean DB, the San Francisco option in the database cannot be loaded. How should I populate the dropdown box if I have no DB?

One idea is to run the db:seed from seed.rb but I'd rather rely on less assumptions when I run my tests. Is there a way to use something like Factory Girl?

Thanks,

Delos Chang
  • 1,823
  • 3
  • 27
  • 47

1 Answers1

0

For Example, when you have the following capybara test case, use the background block to setup the data you need for your testing

feature "Signing in" do   
  background do
    Option.create(:name => "San Francisco", :value => "something") #you could also use FactoryGirl.create(:option)   
  end

  scenario "Signing in with correct credentials" do
    visit '/sessions/new'
    fill_in 'Login', :with => 'user@example.com'
    fill_in 'Password', :with => 'caplin'
    click_link 'Sign in'
    expect(page).to have_content 'Success'
  end 
end

Here is the link for factory_girl if you don't know about it already. It comes very handy in setting up data for all kinds of tests.

usha
  • 28,973
  • 5
  • 72
  • 93