diff --git a/lib/capybara/spec/session/all_spec.rb b/lib/capybara/spec/session/all_spec.rb index 15fe8ed0c..413bea52c 100644 --- a/lib/capybara/spec/session/all_spec.rb +++ b/lib/capybara/spec/session/all_spec.rb @@ -48,22 +48,23 @@ @session.all('h1').first.text.should == 'This is a test' @session.all("input[id='test_field']").first[:value].should == 'monkey' end - after { Capybara.default_selector = :xpath } end context "with visible filter" do - after { Capybara.ignore_hidden_elements = true } - it "should only find visible nodes" do - @session.all(:css, "a.simple").should have(1).elements - Capybara.ignore_hidden_elements = false - @session.all(:css, "a.simple").should have(2).elements + it "should only find visible nodes when true" do @session.all(:css, "a.simple", :visible => true).should have(1).elements end - it "should only find invisible nodes" do - Capybara.ignore_hidden_elements = true + it "should find nodes regardless of whether they are invisible when false" do @session.all(:css, "a.simple", :visible => false).should have(2).elements end + + it "should default to Capybara.ignore_hidden_elements" do + Capybara.ignore_hidden_elements = true + @session.all(:css, "a.simple").should have(1).elements + Capybara.ignore_hidden_elements = false + @session.all(:css, "a.simple").should have(2).elements + end end context "within a scope" do diff --git a/lib/capybara/spec/session/first_spec.rb b/lib/capybara/spec/session/first_spec.rb index 30ee66edf..6875ceedb 100644 --- a/lib/capybara/spec/session/first_spec.rb +++ b/lib/capybara/spec/session/first_spec.rb @@ -38,22 +38,24 @@ @session.first('h1').text.should == 'This is a test' @session.first("input[id='test_field']")[:value].should == 'monkey' end - after { Capybara.default_selector = :xpath } end context "with visible filter" do - after { Capybara.ignore_hidden_elements = false } - it "should only find visible nodes if true given" do - @session.first(:css, "a#invisible").should_not be_nil + it "should only find visible nodes when true" do @session.first(:css, "a#invisible", :visible => true).should be_nil - Capybara.ignore_hidden_elements = true - @session.first(:css, "a#invisible").should be_nil end - it "should include invisible nodes if false given" do - Capybara.ignore_hidden_elements = true + it "should find nodes regardless of whether they are invisible when false" do @session.first(:css, "a#invisible", :visible => false).should_not be_nil + @session.first(:css, "a", :visible => false).should_not be_nil + end + + it "should default to Capybara.ignore_hidden_elements" do + Capybara.ignore_hidden_elements = true @session.first(:css, "a#invisible").should be_nil + Capybara.ignore_hidden_elements = false + @session.first(:css, "a#invisible").should_not be_nil + @session.first(:css, "a").should_not be_nil end end diff --git a/lib/capybara/spec/session/node_spec.rb b/lib/capybara/spec/session/node_spec.rb index a039947f1..9e5a601c2 100644 --- a/lib/capybara/spec/session/node_spec.rb +++ b/lib/capybara/spec/session/node_spec.rb @@ -83,6 +83,7 @@ describe "#visible?" do it "should extract node visibility" do + Capybara.ignore_hidden_elements = false @session.first('//a').should be_visible @session.find('//div[@id="hidden"]').should_not be_visible diff --git a/lib/capybara/spec/spec_helper.rb b/lib/capybara/spec/spec_helper.rb index 0b1700179..7cebf6238 100644 --- a/lib/capybara/spec/spec_helper.rb +++ b/lib/capybara/spec/spec_helper.rb @@ -19,6 +19,7 @@ def reset! Capybara.app_host = nil Capybara.default_selector = :xpath Capybara.default_wait_time = 1 + Capybara.ignore_hidden_elements = true Capybara.exact = false Capybara.match = :smart end