I am having an issue where a feature works fine but the corresponding
test fails, and I can’t understand why.
I created a mock application to demonstrate the problem.
https://github.com/assafshomer/clear_button
All it does is show an input form with a clear button. The clearing
happens by redirecting back to the same form. It does clear it when you
run the app, but the test for it fails.
If you feel inclined to help, please clone the repo and run the test
mentioned in the readme (or the full suite, which is very short). The
test fails (at least for me) but if you run the app
(http://localhost:3000/pages/input) the ‘Clear’ button does seem
to be doing the right thing.
Help?
On Sun, May 12, 2013 at 3:11 PM, Assaf S. [email protected]
wrote:
If you feel inclined to help, please clone the repo and run the test
mentioned in the readme (or the full suite, which is very short). The
test fails (at least for me) but if you run the app
(http://localhost:3000/pages/input) the ‘Clear’ button does seem
to be doing the right thing.
Help?
Just a quick glance, but you probably should move lines 10-16 (the
before and it blocks) inside their own describe block, as the before
block at line 10 is also running before every it in the other describe
blocks.
tamouse mailing lists wrote in post #1108701:
On Sun, May 12, 2013 at 3:11 PM, Assaf S. [email protected]
wrote:
If you feel inclined to help, please clone the repo and run the test
mentioned in the readme (or the full suite, which is very short). The
test fails (at least for me) but if you run the app
(http://localhost:3000/pages/input) the ‘Clear’ button does seem
to be doing the right thing.
Help?
Just a quick glance, but you probably should move lines 10-16 (the
before and it blocks) inside their own describe block, as the before
block at line 10 is also running before every it in the other describe
blocks.
Thanks. Moved test inside a describe block.
Problem still remains though.
Any other ideas?
On Sun, May 12, 2013 at 4:46 PM, Assaf S. [email protected]
wrote:
Just a quick glance, but you probably should move lines 10-16 (the
before and it blocks) inside their own describe block, as the before
block at line 10 is also running before every it in the other describe
blocks.
Thanks. Moved test inside a describe block.
Problem still remains though.
Both the before at line 10 through the end of the it test at line 16
need to be in their own describe block, not just the test.
tamouse mailing lists wrote in post #1108719:
On Sun, May 12, 2013 at 4:46 PM, Assaf S. [email protected]
wrote:
Just a quick glance, but you probably should move lines 10-16 (the
before and it blocks) inside their own describe block, as the before
block at line 10 is also running before every it in the other describe
blocks.
Thanks. Moved test inside a describe block.
Problem still remains though.
Both the before at line 10 through the end of the it test at line 16
need to be in their own describe block, not just the test.
Thanks for the response, but I’m confused, Is this not what I just did
in the last push?
Before:
require ‘spec_helper’
describe “Pages” do
subject { page }
before { visit ‘/pages/input’}
describe “search” do
it { should have_selector(‘input#show_button’) }
it { should have_selector(‘input#clear_button’) }
end
before do
fill_in ‘input_field’, with: ‘blah’
click_button ‘Show’
end
it “should display the string ‘blah’” do
page.should have_selector(‘h3’, text: ‘blah’)
end
describe ‘clear button’ do
before { click_button ‘Clear’ }
it “should not show the string ‘blah’” do
page.should_not have_selector(‘h3’, text: ‘blah’)
end
end
end
now:
require ‘spec_helper’
describe “Pages” do
subject { page }
before { visit ‘/pages/input’}
describe “input form” do
it { should have_selector(‘input#show_button’) }
it { should have_selector(‘input#clear_button’) }
end
describe “show button” do
before do
fill_in ‘input_field’, with: ‘blah’
click_button ‘Show’
end
it “should display the string ‘blah’” do
page.should have_selector(‘h3’, text: ‘blah’)
end
end
describe ‘clear button’ do
before do
fill_in ‘input_field’, with: ‘blah’
click_button ‘Show’
click_button ‘Clear’
end
it “should not show the string ‘blah’” do
page.should_not have_selector(‘h3’, text: ‘blah’)
end
end
end
Bottom line, test still fails.
any other suggestions?
let me push my change up and do a PR and see if you can see a diff: it
works for me.
https://github.com/assafshomer/clear_button/pull/1
On Mon, May 13, 2013 at 11:20 PM, tamouse mailing lists
tamouse mailing lists wrote in post #1108881:
https://github.com/assafshomer/clear_button/pull/1
On Mon, May 13, 2013 at 11:20 PM, tamouse mailing lists
Tamouse, thank you.
However, your pull nullifies the test.
Your test clicks the clear button without first writing anything in the
input field, so obviously clearing the empty input field leaves you with
an empty input field.
In order that the test actually tests something, it must first write
something into the input field and then try to clear it.
any other ideas?
and now i’m not going to bother spending any more time on it
On Fri, May 17, 2013 at 11:58 PM, tamouse mailing lists
On Mon, May 13, 2013 at 11:23 PM, tamouse mailing lists
[email protected] wrote:
wrote:
need to be in their own describe block, not just the test.
before { visit ‘/pages/input’}
end
end
before do
Bottom line, test still fails.
any other suggestions?
Okay, as near as I can figure out, capybara is choking on the fact
that you have commit=Show in your query string, you’re using
method=GET in your form, and commit=Clear is coming in the request
body. Somehow, when rails is called by the browser, this is handled in
the way you want (which is the request body’s commit=Clear overrides
the one in the query string), but in capybara, it isn’t.