1

How can I write a test to check the path on a form?

I'm trying this:

it "has a proper form path given subdomains" do    
  @event = Factory :event
  get events_path(@event), nil,  {'HTTP_HOST' => 'staging.example.com' }
  page.should have_selector "form", :action => "secure.staging.example.com"
end

But it doesn't look like my test is working:

 Failure/Error: page.should have_selector "form", :action => "secure.staging.example.com"
   expected css "form" to return something
 # ./spec/requests/events_spec.rb:18:in `block (3 levels) in <top (required)>'
Valeh Hajiyev
  • 3,216
  • 4
  • 19
  • 28
manafire
  • 5,984
  • 4
  • 43
  • 53

1 Answers1

1

I learned a lot about testing in solving this like the difference between page and response variables.

What I really needed to do was write a helper spec to test that my url_for helper method was prepending subdomains properly. But I also figured out the view spec code:

it "has a proper form path given subdomains" do    
  assign :event, Factory(:event)

  controller.request.host = "staging.example.com"

  render

  assert_select "form[action*=?]", "secure.staging.example.com"
end
Community
  • 1
  • 1
manafire
  • 5,984
  • 4
  • 43
  • 53