Capybara with redirect

62 views
Skip to first unread message

Assaf Shomer

unread,
May 12, 2013, 4:11:25 PM5/12/13
to rubyonra...@googlegroups.com
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?

--
Posted via http://www.ruby-forum.com/.

tamouse mailing lists

unread,
May 12, 2013, 4:46:34 PM5/12/13
to rubyonra...@googlegroups.com
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.

Assaf Shomer

unread,
May 12, 2013, 5:46:40 PM5/12/13
to rubyonra...@googlegroups.com
tamouse mailing lists wrote in post #1108701:
Thanks. Moved test inside a describe block.
Problem still remains though.

Any other ideas?

tamouse mailing lists

unread,
May 12, 2013, 11:44:54 PM5/12/13
to rubyonra...@googlegroups.com
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.

Assaf Shomer

unread,
May 13, 2013, 1:28:17 AM5/13/13
to rubyonra...@googlegroups.com
tamouse mailing lists wrote in post #1108719:
I think this is what I did in the last push, isn't it?

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?

tamouse mailing lists

unread,
May 14, 2013, 12:20:20 AM5/14/13
to rubyonra...@googlegroups.com
let me push my change up and do a PR and see if you can see a diff: it
works for me.
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

tamouse mailing lists

unread,
May 14, 2013, 12:23:10 AM5/14/13
to rubyonra...@googlegroups.com

tamouse mailing lists

unread,
May 14, 2013, 1:55:54 AM5/14/13
to rubyonra...@googlegroups.com
On Mon, May 13, 2013 at 11:23 PM, tamouse mailing lists
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.

Assaf Shomer

unread,
May 17, 2013, 2:44:20 AM5/17/13
to rubyonra...@googlegroups.com
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?

tamouse mailing lists

unread,
May 18, 2013, 12:58:27 AM5/18/13
to rubyonra...@googlegroups.com
maybe read my follow up
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/42695ad05dd16b831fc84d9e40debf18%40ruby-forum.com?hl=en-US.

tamouse mailing lists

unread,
May 18, 2013, 12:58:50 AM5/18/13
to rubyonra...@googlegroups.com
and now i'm not going to bother spending any more time on it
Reply all
Reply to author
Forward
0 new messages