Skip to content
Browse files

update specs to be more condensed

  • Loading branch information...
1 parent c6103e7 commit 399a8fbfb977e45e0e549c145768a2f38e5b86a1 @willryan willryan committed Mar 10, 2012
Showing with 44 additions and 59 deletions.
  1. +44 −59 spec/driver_spec.rb
View
103 spec/driver_spec.rb
@@ -1436,6 +1436,21 @@ def key_app_body(event)
body
end
+ def charCode_for(character)
+ subject.find("//input")[0].set(character)
+ subject.find("//div[@id='charcode_value']")[0].text
+ end
+
+ def keyCode_for(character)
+ subject.find("//input")[0].set(character)
+ subject.find("//div[@id='keycode_value']")[0].text
+ end
+
+ def which_for(character)
+ subject.find("//input")[0].set(character)
+ subject.find("//div[@id='which_value']")[0].text
+ end
+
context "keypress app" do
before(:all) do
@app = lambda do |env|
@@ -1445,59 +1460,50 @@ def key_app_body(event)
end
it "returns the charCode for the keypressed" do
- subject.find("//input")[0].set("a")
- subject.find("//div[@id='charcode_value']")[0].text.should == "97"
+ charCode_for("a").should == "97"
end
it "returns the keyCode for the keypressed" do
- subject.find("//input")[0].set("a")
- subject.find("//div[@id='keycode_value']")[0].text.should == "97"
- subject.find("//input")[0].set("A")
- subject.find("//div[@id='keycode_value']")[0].text.should == "65"
- subject.find("//input")[0].set("\r")
- subject.find("//div[@id='keycode_value']")[0].text.should == "13"
+ keyCode_for("a").should == "97"
+ keyCode_for("A").should == "65"
+ keyCode_for("\r").should == "13"
end
it "returns the which for the keypressed" do
- subject.find("//input")[0].set("a")
- subject.find("//div[@id='which_value']")[0].text.should == "97"
- subject.find("//input")[0].set("A")
- subject.find("//div[@id='which_value']")[0].text.should == "65"
- subject.find("//input")[0].set("\r")
- subject.find("//div[@id='which_value']")[0].text.should == "13"
+ which_for("a").should == "97"
+ which_for("A").should == "65"
+ which_for("\r").should == "13"
end
end
- context "keydown app" do
- before(:all) do
- @app = lambda do |env|
- body = key_app_body("keydown")
- [200, { 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s }, [body]]
- end
+ shared_examples "a keyupdown app" do
+ it "returns a 0 charCode for the event" do
+ charCode_for("a").should == "0"
+ charCode_for("A").should == "0"
+ charCode_for("\r").should == "0"
end
- it "returns 0 charCode for the keyup" do
- subject.find("//input")[0].set("a")
- subject.find("//div[@id='charcode_value']")[0].text.should == "0"
+ it "returns the keyCode for the event" do
+ keyCode_for("a").should == "65"
+ keyCode_for("A").should == "65"
+ keyCode_for("\r").should == "13"
end
- it "returns the keyCode for the keyup" do
- subject.find("//input")[0].set("a")
- subject.find("//div[@id='keycode_value']")[0].text.should == "65"
- subject.find("//input")[0].set("A")
- subject.find("//div[@id='keycode_value']")[0].text.should == "65"
- subject.find("//input")[0].set("\r")
- subject.find("//div[@id='keycode_value']")[0].text.should == "13"
+ it "returns the which for the event" do
+ which_for("a").should == "65"
+ which_for("A").should == "65"
+ which_for("\r").should == "13"
end
+ end
- it "returns the which for the keyup" do
- subject.find("//input")[0].set("a")
- subject.find("//div[@id='which_value']")[0].text.should == "65"
- subject.find("//input")[0].set("A")
- subject.find("//div[@id='which_value']")[0].text.should == "65"
- subject.find("//input")[0].set("\r")
- subject.find("//div[@id='which_value']")[0].text.should == "13"
+ context "keydown app" do
+ before(:all) do
+ @app = lambda do |env|
+ body = key_app_body("keydown")
+ [200, { 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s }, [body]]
+ end
end
+ it_behaves_like "a keyupdown app"
end
context "keyup app" do
@@ -1508,27 +1514,6 @@ def key_app_body(event)
end
end
- it "returns 0 charCode for the keyup" do
- subject.find("//input")[0].set("a")
- subject.find("//div[@id='charcode_value']")[0].text.should == "0"
- end
-
- it "returns the keyCode for the keyup" do
- subject.find("//input")[0].set("a")
- subject.find("//div[@id='keycode_value']")[0].text.should == "65"
- subject.find("//input")[0].set("A")
- subject.find("//div[@id='keycode_value']")[0].text.should == "65"
- subject.find("//input")[0].set("\r")
- subject.find("//div[@id='keycode_value']")[0].text.should == "13"
- end
-
- it "returns the which for the keyup" do
- subject.find("//input")[0].set("a")
- subject.find("//div[@id='which_value']")[0].text.should == "65"
- subject.find("//input")[0].set("A")
- subject.find("//div[@id='which_value']")[0].text.should == "65"
- subject.find("//input")[0].set("\r")
- subject.find("//div[@id='which_value']")[0].text.should == "13"
- end
+ it_behaves_like "a keyupdown app"
end
end

0 comments on commit 399a8fb

Please sign in to comment.
Something went wrong with that request. Please try again.