0

I am writing a test for my rails app function that handles admission requests to a school. my tests that is currently does not work tests whether the total count of admission requests changes by 1 after submitting an admission request form. this is the test

describe "with valid information" do

  before do
    fill_in "Name",         with: "Example User"
    fill_in "Email",        with: "user@example.com"
    fill_in "Address",     with: "68 High St"
    fill_in "Phone", with: "2035846857"
    fill_in "Card", with: "4242424242424242"
    fill_in "CVC", with: "557"
    fill_in "admission_request_exp_month", with: "08"
    fill_in "admission_request_exp_year", with: "2017"
  end

  it "should create a request", :js => true do
    expect { click_button 'Submit Request' }.to change(AdmissionRequest, :count).by(1)
  end
  ...

this is what I get when I run the test

 1) Admission requests pages new admission request with valid information should create a request
 Failure/Error: expect { click_button 'Submit Request' }.to change(AdmissionRequest, :count).by(1)
   count should have been changed by 1, but was changed by 0

But if I submit the form manually, everything works perfectly fine, a new admission request is saved into the database and the count changes by 1. What might be the problem? I am using rails 3.2.13 and capybara 1.1.2

Thanks

zishe
  • 10,665
  • 12
  • 64
  • 103
Minh Tri Pham
  • 861
  • 3
  • 9
  • 18
  • I think you try create not valid record in test environment. I suggest debug controller/action where params from the form come to. It is very convenient to write `bunding.pry`(add gem `pry-rails`) in the action and check if the object is valid and what errors it has. – gotva Nov 06 '13 at 11:51
  • possible duplicate of [Why does adding "sleep 1" in an after hook cause this Rspec/Capybara test to pass?](http://stackoverflow.com/questions/23554882/why-does-adding-sleep-1-in-an-after-hook-cause-this-rspec-capybara-test-to-pas) – Dave Schweisguth May 31 '14 at 12:27

0 Answers0