diff --git a/spec/driver_rendering_spec.rb b/spec/driver_rendering_spec.rb index 3cb8a19..c9ff9eb 100644 --- a/spec/driver_rendering_spec.rb +++ b/spec/driver_rendering_spec.rb @@ -3,14 +3,10 @@ require 'capybara/webkit/driver' require 'mini_magick' describe Capybara::Webkit::Driver, "rendering an image" do + include AppRunner - before(:all) do - # Set up the tmp directory and file name - tmp_dir = File.join(PROJECT_ROOT, 'tmp') - FileUtils.mkdir_p tmp_dir - @file_name = File.join(tmp_dir, 'render-test.png') - - app = lambda do |env| + let(:driver) do + driver_for_app do |env| body = <<-HTML @@ -22,22 +18,25 @@ describe Capybara::Webkit::Driver, "rendering an image" do { 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s }, [body]] end - - @driver = Capybara::Webkit::Driver.new(app, :browser => $webkit_browser) - @driver.visit("/hello/world?success=true") end - after(:all) { @driver.reset! } + before(:each) do + # Set up the tmp directory and file name + tmp_dir = File.join(PROJECT_ROOT, 'tmp') + FileUtils.mkdir_p tmp_dir + @file_name = File.join(tmp_dir, 'render-test.png') + driver.visit '/' + end def render(options) FileUtils.rm_f @file_name - @driver.render @file_name, options + driver.render @file_name, options @image = MiniMagick::Image.open @file_name end context "with default options" do - before(:all){ render({}) } + before { render({}) } it "should be a PNG" do @image[:format].should == "PNG" @@ -54,7 +53,7 @@ describe Capybara::Webkit::Driver, "rendering an image" do end context "with dimensions set larger than necessary" do - before(:all){ render(:width => 500, :height => 400) } + before { render(:width => 500, :height => 400) } it "width should match the width given" do @image[:width].should == 500 @@ -66,7 +65,7 @@ describe Capybara::Webkit::Driver, "rendering an image" do end context "with dimensions set smaller than the document's default" do - before(:all){ render(:width => 50, :height => 10) } + before { render(:width => 50, :height => 10) } it "width should be greater than the width given" do @image[:width].should > 50 @@ -76,5 +75,4 @@ describe Capybara::Webkit::Driver, "rendering an image" do @image[:height].should > 10 end end - end diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index 42d70ab..4167697 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -3,15 +3,11 @@ require 'capybara/webkit/driver' require 'base64' describe Capybara::Webkit::Driver do - subject { Capybara::Webkit::Driver.new(@app, :browser => $webkit_browser) } - before do - subject.reset! - subject.visit("/hello/world?success=true") - end + include AppRunner context "iframe app" do - before(:all) do - @app = lambda do |env| + let(:driver) do + driver_for_app do |env| params = ::Rack::Utils.parse_query(env['QUERY_STRING']) if params["iframe"] == "true" # We are in an iframe request. @@ -45,71 +41,74 @@ describe Capybara::Webkit::Driver do end end + before do + driver.visit("/") + end + it "finds frames by index" do - subject.within_frame(0) do - subject.find("//*[contains(., 'goodbye')]").should_not be_empty + driver.within_frame(0) do + driver.find("//*[contains(., 'goodbye')]").should_not be_empty end end it "finds frames by id" do - subject.within_frame("f") do - subject.find("//*[contains(., 'goodbye')]").should_not be_empty + driver.within_frame("f") do + driver.find("//*[contains(., 'goodbye')]").should_not be_empty end end it "raises error for missing frame by index" do - expect { subject.within_frame(1) { } }. + expect { driver.within_frame(1) { } }. to raise_error(Capybara::Webkit::InvalidResponseError) end it "raise_error for missing frame by id" do - expect { subject.within_frame("foo") { } }. + expect { driver.within_frame("foo") { } }. to raise_error(Capybara::Webkit::InvalidResponseError) end it "returns an attribute's value" do - subject.within_frame("f") do - subject.find("//p").first["id"].should == "farewell" + driver.within_frame("f") do + driver.find("//p").first["id"].should == "farewell" end end it "returns a node's text" do - subject.within_frame("f") do - subject.find("//p").first.text.should == "goodbye" + driver.within_frame("f") do + driver.find("//p").first.text.should == "goodbye" end end it "returns the current URL" do - subject.within_frame("f") do - port = subject.instance_variable_get("@rack_server").port - subject.current_url.should == "http://127.0.0.1:#{port}/?iframe=true" + driver.within_frame("f") do + driver.current_url.should == driver_url(driver, "/?iframe=true") end end it "returns the source code for the page" do - subject.within_frame("f") do - subject.source.should =~ %r{.*farewell.*}m + driver.within_frame("f") do + driver.source.should =~ %r{.*farewell.*}m end end it "evaluates Javascript" do - subject.within_frame("f") do - result = subject.evaluate_script(%) + driver.within_frame("f") do + result = driver.evaluate_script(%) result.should == "goodbye" end end it "executes Javascript" do - subject.within_frame("f") do - subject.execute_script(%) - subject.find("//p[contains(., 'yo')]").should_not be_empty + driver.within_frame("f") do + driver.execute_script(%) + driver.find("//p[contains(., 'yo')]").should_not be_empty end end end context "error iframe app" do - before(:all) do - @app = lambda do |env| + let(:driver) do + driver_for_app do |env| case env["PATH_INFO"] when "/inner-not-found" [404, {}, []] @@ -131,14 +130,16 @@ describe Capybara::Webkit::Driver do end end + before { driver.visit("/") } + it "raises error whose message references the actual missing url" do - expect { subject.visit("/outer") }.to raise_error(Capybara::Webkit::InvalidResponseError, /inner-not-found/) + expect { driver.visit("/outer") }.to raise_error(Capybara::Webkit::InvalidResponseError, /inner-not-found/) end end context "redirect app" do - before(:all) do - @app = lambda do |env| + let(:driver) do + driver_for_app do |env| if env['PATH_INFO'] == '/target' content_type = "

#{env['CONTENT_TYPE']}

" [200, {"Content-Type" => "text/html", "Content-Length" => content_type.length.to_s}, [content_type]] @@ -159,48 +160,49 @@ describe Capybara::Webkit::Driver do end end + before { driver.visit("/") } + it "should redirect without content type" do - subject.visit("/form") - subject.find("//input").first.click - subject.find("//p").first.text.should == "" + driver.visit("/form") + driver.find("//input").first.click + driver.find("//p").first.text.should == "" end it "returns the current URL when changed by pushState after a redirect" do - subject.visit("/redirect-me") - port = subject.instance_variable_get("@rack_server").port - subject.execute_script("window.history.pushState({}, '', '/pushed-after-redirect')") - subject.current_url.should == "http://127.0.0.1:#{port}/pushed-after-redirect" + driver.visit("/redirect-me") + driver.execute_script("window.history.pushState({}, '', '/pushed-after-redirect')") + driver.current_url.should == driver_url(driver, "/pushed-after-redirect") end it "returns the current URL when changed by replaceState after a redirect" do - subject.visit("/redirect-me") - port = subject.instance_variable_get("@rack_server").port - subject.execute_script("window.history.replaceState({}, '', '/replaced-after-redirect')") - subject.current_url.should == "http://127.0.0.1:#{port}/replaced-after-redirect" + driver.visit("/redirect-me") + driver.execute_script("window.history.replaceState({}, '', '/replaced-after-redirect')") + driver.current_url.should == driver_url(driver, "/replaced-after-redirect") end end context "css app" do - before(:all) do + let(:driver) do body = "css" - @app = lambda do |env| + driver_for_app do |env| [200, {"Content-Type" => "text/css", "Content-Length" => body.length.to_s}, [body]] end - subject.visit("/") end + before { driver.visit("/") } + it "renders unsupported content types gracefully" do - subject.body.should =~ /css/ + driver.body.should =~ /css/ end it "sets the response headers with respect to the unsupported request" do - subject.response_headers["Content-Type"].should == "text/css" + driver.response_headers["Content-Type"].should == "text/css" end end context "hello app" do - before(:all) do - @app = lambda do |env| + let(:driver) do + driver_for_app do |env| body = <<-HTML @@ -227,166 +229,165 @@ describe Capybara::Webkit::Driver do end end + before { driver.visit("/") } + it "handles anchor tags" do - subject.visit("#test") - subject.find("//*[contains(., 'hello')]").should_not be_empty - subject.visit("#test") - subject.find("//*[contains(., 'hello')]").should_not be_empty + driver.visit("#test") + driver.find("//*[contains(., 'hello')]").should_not be_empty + driver.visit("#test") + driver.find("//*[contains(., 'hello')]").should_not be_empty end it "finds content after loading a URL" do - subject.find("//*[contains(., 'hello')]").should_not be_empty + driver.find("//*[contains(., 'hello')]").should_not be_empty end it "has an empty page after reseting" do - subject.reset! - subject.find("//*[contains(., 'hello')]").should be_empty + driver.reset! + driver.find("//*[contains(., 'hello')]").should be_empty end it "has a blank location after reseting" do - subject.reset! - subject.current_url.should == "" + driver.reset! + driver.current_url.should == "" end it "raises an error for an invalid xpath query" do - expect { subject.find("totally invalid salad") }. + expect { driver.find("totally invalid salad") }. to raise_error(Capybara::Webkit::InvalidResponseError, /xpath/i) end it "returns an attribute's value" do - subject.find("//p").first["id"].should == "greeting" + driver.find("//p").first["id"].should == "greeting" end it "parses xpath with quotes" do - subject.find('//*[contains(., "hello")]').should_not be_empty + driver.find('//*[contains(., "hello")]').should_not be_empty end it "returns a node's text" do - subject.find("//p").first.text.should == "hello" + driver.find("//p").first.text.should == "hello" end it "normalizes a node's text" do - subject.find("//div[contains(@class, 'normalize')]").first.text.should == "Spaces not normalized" + driver.find("//div[contains(@class, 'normalize')]").first.text.should == "Spaces not normalized" end it "returns the current URL" do - port = subject.instance_variable_get("@rack_server").port - subject.current_url.should == "http://127.0.0.1:#{port}/hello/world?success=true" + driver.visit "/hello/world?success=true" + driver.current_url.should == driver_url(driver, "/hello/world?success=true") end it "returns the current URL when changed by pushState" do - port = subject.instance_variable_get("@rack_server").port - subject.execute_script("window.history.pushState({}, '', '/pushed')") - subject.current_url.should == "http://127.0.0.1:#{port}/pushed" + driver.execute_script("window.history.pushState({}, '', '/pushed')") + driver.current_url.should == driver_url(driver, "/pushed") end it "returns the current URL when changed by replaceState" do - port = subject.instance_variable_get("@rack_server").port - subject.execute_script("window.history.replaceState({}, '', '/replaced')") - subject.current_url.should == "http://127.0.0.1:#{port}/replaced" + driver.execute_script("window.history.replaceState({}, '', '/replaced')") + driver.current_url.should == driver_url(driver, "/replaced") end it "does not double-encode URLs" do - subject.visit("/hello/world?success=%25true") - subject.current_url.should =~ /success=\%25true/ + driver.visit("/hello/world?success=%25true") + driver.current_url.should =~ /success=\%25true/ end it "visits a page with an anchor" do - subject.visit("/hello#display_none") - subject.current_url.should =~ /hello#display_none/ + driver.visit("/hello#display_none") + driver.current_url.should =~ /hello#display_none/ end it "returns the source code for the page" do - subject.source.should =~ %r{.*greeting.*}m + driver.source.should =~ %r{.*greeting.*}m end it "evaluates Javascript and returns a string" do - result = subject.evaluate_script(%) + result = driver.evaluate_script(%) result.should == "hello" end it "evaluates Javascript and returns an array" do - result = subject.evaluate_script(%<["hello", "world"]>) + result = driver.evaluate_script(%<["hello", "world"]>) result.should == %w(hello world) end it "evaluates Javascript and returns an int" do - result = subject.evaluate_script(%<123>) + result = driver.evaluate_script(%<123>) result.should == 123 end it "evaluates Javascript and returns a float" do - result = subject.evaluate_script(%<1.5>) + result = driver.evaluate_script(%<1.5>) result.should == 1.5 end it "evaluates Javascript and returns null" do - result = subject.evaluate_script(%<(function () {})()>) + result = driver.evaluate_script(%<(function () {})()>) result.should == nil end it "evaluates Javascript and returns an object" do - result = subject.evaluate_script(%<({ 'one' : 1 })>) + result = driver.evaluate_script(%<({ 'one' : 1 })>) result.should == { 'one' => 1 } end it "evaluates Javascript and returns true" do - result = subject.evaluate_script(%) + result = driver.evaluate_script(%) result.should === true end it "evaluates Javascript and returns false" do - result = subject.evaluate_script(%) + result = driver.evaluate_script(%) result.should === false end it "evaluates Javascript and returns an escaped string" do - result = subject.evaluate_script(%<'"'>) + result = driver.evaluate_script(%<'"'>) result.should === "\"" end it "evaluates Javascript with multiple lines" do - result = subject.evaluate_script("[1,\n2]") + result = driver.evaluate_script("[1,\n2]") result.should == [1, 2] end it "executes Javascript" do - subject.execute_script(%) - subject.find("//p[contains(., 'yo')]").should_not be_empty + driver.execute_script(%) + driver.find("//p[contains(., 'yo')]").should_not be_empty end it "raises an error for failing Javascript" do - expect { subject.execute_script(%) }. + expect { driver.execute_script(%) }. to raise_error(Capybara::Webkit::InvalidResponseError) end it "doesn't raise an error for Javascript that doesn't return anything" do - lambda { subject.execute_script(%<(function () { "returns nothing" })()>) }. + lambda { driver.execute_script(%<(function () { "returns nothing" })()>) }. should_not raise_error end it "returns a node's tag name" do - subject.find("//p").first.tag_name.should == "p" + driver.find("//p").first.tag_name.should == "p" end it "reads disabled property" do - subject.find("//input").first.should be_disabled + driver.find("//input").first.should be_disabled end it "reads checked property" do - subject.find("//input[@id='checktest']").first.should be_checked + driver.find("//input[@id='checktest']").first.should be_checked end it "finds visible elements" do - subject.find("//p").first.should be_visible - subject.find("//*[@id='invisible']").first.should_not be_visible + driver.find("//p").first.should be_visible + driver.find("//*[@id='invisible']").first.should_not be_visible end end context "console messages app" do - - before(:all) do - @app = lambda do |env| + let(:driver) do + driver_for_app do |env| body = <<-HTML @@ -406,20 +407,22 @@ describe Capybara::Webkit::Driver do end end + before { driver.visit("/") } + it "collects messages logged to the console" do - subject.console_messages.first.should include :source, :message => "hello", :line_number => 6 - subject.console_messages.length.should eq 3 + driver.console_messages.first.should include :source, :message => "hello", :line_number => 6 + driver.console_messages.length.should eq 3 end it "logs errors to the console" do - subject.error_messages.length.should eq 1 + driver.error_messages.length.should eq 1 end end context "form app" do - before(:all) do - @app = lambda do |env| + let(:driver) do + driver_for_app do |env| body = <<-HTML
@@ -453,68 +456,70 @@ describe Capybara::Webkit::Driver do end end + before { driver.visit("/") } + it "returns a textarea's value" do - subject.find("//textarea").first.value.should == "what a wonderful area for text" + driver.find("//textarea").first.value.should == "what a wonderful area for text" end it "returns a text input's value" do - subject.find("//input").first.value.should == "bar" + driver.find("//input").first.value.should == "bar" end it "returns a select's value" do - subject.find("//select").first.value.should == "Capybara" + driver.find("//select").first.value.should == "Capybara" end it "sets an input's value" do - input = subject.find("//input").first + input = driver.find("//input").first input.set("newvalue") input.value.should == "newvalue" end it "sets an input's value greater than the max length" do - input = subject.find("//input[@name='maxlength_foo']").first + input = driver.find("//input[@name='maxlength_foo']").first input.set("allegories (poems)") input.value.should == "allegories" end it "sets an input's value equal to the max length" do - input = subject.find("//input[@name='maxlength_foo']").first + input = driver.find("//input[@name='maxlength_foo']").first input.set("allegories") input.value.should == "allegories" end it "sets an input's value less than the max length" do - input = subject.find("//input[@name='maxlength_foo']").first + input = driver.find("//input[@name='maxlength_foo']").first input.set("poems") input.value.should == "poems" end it "sets an input's nil value" do - input = subject.find("//input").first + input = driver.find("//input").first input.set(nil) input.value.should == "" end it "sets a select's value" do - select = subject.find("//select").first + select = driver.find("//select").first select.set("Monkey") select.value.should == "Monkey" end it "sets a textarea's value" do - textarea = subject.find("//textarea").first + textarea = driver.find("//textarea").first textarea.set("newvalue") textarea.value.should == "newvalue" end - let(:monkey_option) { subject.find("//option[@id='select-option-monkey']").first } - let(:capybara_option) { subject.find("//option[@id='select-option-capybara']").first } - let(:animal_select) { subject.find("//select[@name='animal']").first } - let(:apple_option) { subject.find("//option[@id='topping-apple']").first } - let(:banana_option) { subject.find("//option[@id='topping-banana']").first } - let(:cherry_option) { subject.find("//option[@id='topping-cherry']").first } - let(:toppings_select) { subject.find("//select[@name='toppings']").first } - let(:reset_button) { subject.find("//button[@type='reset']").first } + let(:monkey_option) { driver.find("//option[@id='select-option-monkey']").first } + let(:capybara_option) { driver.find("//option[@id='select-option-capybara']").first } + let(:animal_select) { driver.find("//select[@name='animal']").first } + let(:apple_option) { driver.find("//option[@id='topping-apple']").first } + let(:banana_option) { driver.find("//option[@id='topping-banana']").first } + let(:cherry_option) { driver.find("//option[@id='topping-cherry']").first } + let(:toppings_select) { driver.find("//select[@name='toppings']").first } + let(:reset_button) { driver.find("//button[@type='reset']").first } context "a select element's selection has been changed" do before do @@ -569,8 +574,8 @@ describe Capybara::Webkit::Driver do toppings_select.value.should include("Apple", "Banana", "Cherry") end - let(:checked_box) { subject.find("//input[@name='checkedbox']").first } - let(:unchecked_box) { subject.find("//input[@name='uncheckedbox']").first } + let(:checked_box) { driver.find("//input[@name='checkedbox']").first } + let(:unchecked_box) { driver.find("//input[@name='uncheckedbox']").first } it "knows a checked box is checked" do checked_box['checked'].should be_true @@ -608,8 +613,8 @@ describe Capybara::Webkit::Driver do unchecked_box.should_not be_checked end - let(:enabled_input) { subject.find("//input[@name='foo']").first } - let(:disabled_input) { subject.find("//input[@id='disabled_input']").first } + let(:enabled_input) { driver.find("//input[@name='foo']").first } + let(:disabled_input) { driver.find("//input[@id='disabled_input']").first } it "knows a disabled input is disabled" do disabled_input['disabled'].should be_true @@ -621,8 +626,8 @@ describe Capybara::Webkit::Driver do end context "dom events" do - before(:all) do - @app = lambda do |env| + let(:driver) do + driver_for_app do |env| body = <<-HTML @@ -652,15 +657,17 @@ describe Capybara::Webkit::Driver do end end + before { driver.visit("/") } + it "triggers mouse events" do - subject.find("//a").first.click - subject.find("//li").map(&:text).should == %w(mousedown mouseup click) + driver.find("//a").first.click + driver.find("//li").map(&:text).should == %w(mousedown mouseup click) end end context "form events app" do - before(:all) do - @app = lambda do |env| + let(:driver) do + driver_for_app do |env| body = <<-HTML @@ -707,6 +714,8 @@ describe Capybara::Webkit::Driver do end end + before { driver.visit("/") } + let(:newtext) { 'newvalue' } let(:keyevents) do @@ -717,30 +726,30 @@ describe Capybara::Webkit::Driver do %w(email number password search tel text url).each do | field_type | it "triggers text input events on inputs of type #{field_type}" do - subject.find("//input[@type='#{field_type}']").first.set(newtext) - subject.find("//li").map(&:text).should == keyevents + driver.find("//input[@type='#{field_type}']").first.set(newtext) + driver.find("//li").map(&:text).should == keyevents end end it "triggers textarea input events" do - subject.find("//textarea").first.set(newtext) - subject.find("//li").map(&:text).should == keyevents + driver.find("//textarea").first.set(newtext) + driver.find("//li").map(&:text).should == keyevents end it "triggers radio input events" do - subject.find("//input[@type='radio']").first.set(true) - subject.find("//li").map(&:text).should == %w(mousedown mouseup change click) + driver.find("//input[@type='radio']").first.set(true) + driver.find("//li").map(&:text).should == %w(mousedown mouseup change click) end it "triggers checkbox events" do - subject.find("//input[@type='checkbox']").first.set(true) - subject.find("//li").map(&:text).should == %w(mousedown mouseup change click) + driver.find("//input[@type='checkbox']").first.set(true) + driver.find("//li").map(&:text).should == %w(mousedown mouseup change click) end end context "mouse app" do - before(:all) do - @app =lambda do |env| + let(:driver) do + driver_for_app do |env| body = <<-HTML
Change me
@@ -779,43 +788,45 @@ describe Capybara::Webkit::Driver do end end + before { driver.visit("/") } + it "clicks an element" do - subject.find("//a").first.click - subject.current_url =~ %r{/next$} + driver.find("//a").first.click + driver.current_url =~ %r{/next$} end it "fires a mouse event" do - subject.find("//*[@id='mouseup']").first.trigger("mouseup") - subject.find("//*[@class='triggered']").should_not be_empty + driver.find("//*[@id='mouseup']").first.trigger("mouseup") + driver.find("//*[@class='triggered']").should_not be_empty end it "fires a non-mouse event" do - subject.find("//*[@id='change']").first.trigger("change") - subject.find("//*[@class='triggered']").should_not be_empty + driver.find("//*[@id='change']").first.trigger("change") + driver.find("//*[@class='triggered']").should_not be_empty end it "fires a change on select" do - select = subject.find("//select").first + select = driver.find("//select").first select.value.should == "1" - option = subject.find("//option[@id='option-2']").first + option = driver.find("//option[@id='option-2']").first option.select_option select.value.should == "2" - subject.find("//select[@class='triggered']").should_not be_empty + driver.find("//select[@class='triggered']").should_not be_empty end it "fires drag events" do - draggable = subject.find("//*[@id='mousedown']").first - container = subject.find("//*[@id='mouseup']").first + draggable = driver.find("//*[@id='mousedown']").first + container = driver.find("//*[@id='mouseup']").first draggable.drag_to(container) - subject.find("//*[@class='triggered']").size.should == 1 + driver.find("//*[@class='triggered']").size.should == 1 end end context "nesting app" do - before(:all) do - @app = lambda do |env| + let(:driver) do + driver_for_app do |env| body = <<-HTML
@@ -830,16 +841,18 @@ describe Capybara::Webkit::Driver do end end + before { driver.visit("/") } + it "evaluates nested xpath expressions" do - parent = subject.find("//*[@id='parent']").first + parent = driver.find("//*[@id='parent']").first parent.find("./*[@class='find']").map(&:text).should == %w(Expected) end end context "slow app" do - before(:all) do + let(:driver) do @result = "" - @app = lambda do |env| + driver_for_app do |env| if env["PATH_INFO"] == "/result" sleep(0.5) @result << "finished" @@ -851,15 +864,17 @@ describe Capybara::Webkit::Driver do end end + before { driver.visit("/") } + it "waits for a request to load" do - subject.find("//a").first.click + driver.find("//a").first.click @result.should == "finished" end end context "error app" do - before(:all) do - @app = lambda do |env| + let(:driver) do + driver_for_app do |env| if env['PATH_INFO'] == "/error" [404, {}, []] else @@ -875,11 +890,13 @@ describe Capybara::Webkit::Driver do end end + before { driver.visit("/") } + it "raises a webkit error for the requested url" do expect { - subject.find("//input").first.click + driver.find("//input").first.click wait_for_error_to_complete - subject.find("//body") + driver.find("//body") }. to raise_error(Capybara::Webkit::InvalidResponseError, %r{/error}) end @@ -890,8 +907,8 @@ describe Capybara::Webkit::Driver do end context "slow error app" do - before(:all) do - @app = lambda do |env| + let(:driver) do + driver_for_app do |env| if env['PATH_INFO'] == "/error" body = "error" sleep(1) @@ -910,17 +927,19 @@ describe Capybara::Webkit::Driver do end end + before { driver.visit("/") } + it "raises a webkit error and then continues" do - subject.find("//input").first.click - expect { subject.find("//p") }.to raise_error(Capybara::Webkit::InvalidResponseError) - subject.visit("/") - subject.find("//p").first.text.should == "hello" + driver.find("//input").first.click + expect { driver.find("//p") }.to raise_error(Capybara::Webkit::InvalidResponseError) + driver.visit("/") + driver.find("//p").first.text.should == "hello" end end context "popup app" do - before(:all) do - @app = lambda do |env| + let(:driver) do + driver_for_app do |env| body = <<-HTML