cucumber-nagios
cucumber-nagios copied to clipboard
Submitting forms doesn't work
When I fill out a form and submit, it doesn't pass along the form values, it only submits an empty form.
Test server:
require 'rubygems'
require 'sinatra'
get '/' do
<<-EOF
<html>
<head><title>Testing submitting forms</title></head>
<body>
Log In
<form method="post" action="/" id="myform">
<label for="username"><input id="username" name="username">
<label for="password"><input id="password" name="password" type="password">
<input type="submit" value="Log In">
</form>
</body>
</html>
EOF
end
post '/' do
<<-EOF
<html>
<head><title>Testing cucumber</title></head>
<body>
Values: #{params[:username]}, #{params[:password]}
</body>
</html>
EOF
end
Feature:
Feature: Submitting form
cucumber-nagios should be able to submit forms
Scenario: Visiting home page
When I go to "http://localhost:4567/"
And I fill in "username" with "my user"
And I fill in "password" with "my password"
And I press "Log In"
Then the request should succeed
And I should see "Values: my user, my password"
Output:
Feature: Submitting form
cucumber-nagios should be able to submit forms
Scenario: Visiting home page # features/testing/submitting_forms.feature:4
When I go to "http://localhost:4567/" # features/steps/http_steps.rb:11
And I fill in "username" with "my user" # features/steps/http_steps.rb:23
And I fill in "password" with "my password" # features/steps/http_steps.rb:23
And I press "Log In" # features/steps/http_steps.rb:15
Then the request should succeed # features/steps/http_steps.rb:64
And I should see "Values: my user, my password" # features/steps/http_steps.rb:52
expected: /Values: my user, my password/m
got: " <html>\n <head><title>Testing cucumber</title></head>\n <body>\n Values: , \n </body>\n </html>\n" (using =~)
Diff:
@@ -1,2 +1,7 @@
-/Values: my user, my password/m
+ <html>
+ <head><title>Testing cucumber</title></head>
+ <body>
+ Values: ,
+ </body>
+ </html>
(RSpec::Expectations::ExpectationNotMetError)
./features/steps/http_steps.rb:53:in `/^I should see "(.*)"$/'
features/testing/submitting_forms.feature:10:in `And I should see "Values: my user, my password"'
Failing Scenarios:
cucumber features/testing/submitting_forms.feature:4 # Scenario: Visiting home page
1 scenario (1 failed)
6 steps (1 failed, 5 passed)
0m0.030s
This is my Gemfile.lock:
GEM
remote: http://rubygems.org/
specs:
amqp (0.6.7)
eventmachine (>= 0.12.4)
builder (3.0.0)
cucumber (0.10.6)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
gherkin (~> 2.4.0)
json (>= 1.4.6)
term-ansicolor (>= 1.0.5)
cucumber-nagios (0.9.2)
amqp (= 0.6.7)
bundler (~> 1.0.7)
cucumber (>= 0.10.0)
mechanize (= 1.0.0)
net-ssh (~> 2.1.0)
rspec (>= 2.3.0)
templater (>= 1.0.0)
webrat (= 0.7.2)
diff-lcs (1.1.2)
eventmachine (0.12.10)
extlib (0.9.15)
gherkin (2.4.0)
json (>= 1.4.6)
highline (1.6.2)
json (1.5.2)
mechanize (1.0.0)
nokogiri (>= 1.2.1)
net-ssh (2.1.4)
nokogiri (1.4.4)
rack (1.3.0)
rack-test (0.6.0)
rack (>= 1.0)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
rspec-mocks (~> 2.6.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
templater (1.0.0)
diff-lcs (>= 1.1.2)
extlib (>= 0.9.5)
highline (>= 1.4.0)
term-ansicolor (1.0.5)
webrat (0.7.2)
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
PLATFORMS
ruby
DEPENDENCIES
cucumber-nagios
I thought it might be an issue with webrat, but I created a webrat spec to do the same test and it passes:
it "should submit forms" do
visit "http://localhost:4567/"
fill_in "username", :with => "my username"
fill_in "password", :with => "my password"
response = click_button "Log In"
response.should contain("Values: my username, my password")
end
I can confirm. For the lazy, I've dropped this in a git repo: https://github.com/josephholsten/cuke-nag-forms-test
Looks like the response object is getting messed up. Very weird.
I had the same issue with submitting forms, googled for while and found workaround - in features/support/env.rb one should have this to have webrat doing right job:
Webrat.configure do |config|
config.mode = :rails
config.open_error_files = false
end
This worked for me, appreciate the heads up!
Webrat.configure do |config|
config.mode = :rails
config.open_error_files = false
end