0

I'm a ruby/rails newbie and the application I'm developing starts with a HTTP post from another website which passes in some data and then displays some data capture screens before calling a web service.

I want to start this project using an outside in approach using Cucumber for integration tests and rspec for functional/unit testing.

Using Cucumber how do I simulate the post from the external website so that I can test the flows with the application.

Niall
  • 138
  • 1
  • 8

2 Answers2

1

It doesn't really matter to the application where the call originated; only that the parameters supplied match the expected ones from the referring page. If you depend on a specific HTTP_REFERER being set, check out this answer on how to set a header in Cucumber.

add_headers({'HTTP_REFERER' => 'http://referringsite.com'})

Since you already know which query parameters/headers your app expects from the referring site you can create a setup block that will set these appropriately for each cuke.

Community
  • 1
  • 1
whazzmaster
  • 566
  • 1
  • 4
  • 16
  • Sorry, either I totally lost or I didn't get my question across properly. What I'm looking to do is from capybara post a request. I can't simply navigate to the view and fill in and post the form because there is no view. – Niall Sep 13 '11 at 16:01
0

If you are using Cucumber with Capybara you can do a HTTP POST like this.

When /^I sign in$/ do
  @user = Factory(:user)
  get "/login"
  page.driver.post sessions_path, :username => @user.username, :password =>   @user.password
end

Alternatively if you have a view it would be something like this.

When /^I sign in$/ do
  @user = Factory(:user)
  visit "/login"
  fill_in "Username", :with => @user.username
  fill_in "Password", :with => @user.password
  click_button "Log in"
end
Indika K
  • 1,332
  • 17
  • 27