From 5eacd085dac60fe545542ed0282044141e6680ff Mon Sep 17 00:00:00 2001 From: Marc Schwieterman Date: Sun, 5 Feb 2012 10:25:57 -0500 Subject: [PATCH] create specs to define current_url/pushState behavior --- spec/driver_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index 1da50944..e9ff6b0c 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -132,6 +132,20 @@ subject.find("//input").first.click subject.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" + 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" + end end context "css app" do @@ -223,6 +237,18 @@ subject.current_url.should == "http://127.0.0.1:#{port}/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" + 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" + end + it "does not double-encode URLs" do subject.visit("/hello/world?success=%25true") subject.current_url.should =~ /success=\%25true/