Created
June 16, 2009 00:51
-
-
Save brynary/130456 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/spec/public/choose_spec.rb b/spec/public/choose_spec.rb | |
index 5a07c17..5b4f954 100644 | |
--- a/spec/public/choose_spec.rb | |
+++ b/spec/public/choose_spec.rb | |
@@ -1,6 +1,38 @@ | |
-require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") | |
+# require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") | |
+webrat_path = File.expand_path(File.dirname(__FILE__) + "/../../lib/") | |
+$LOAD_PATH.unshift(webrat_path) unless $LOAD_PATH.include?(webrat_path) | |
+ | |
+require "spec" | |
+require "rack/test" | |
+require "webrat" | |
+ | |
+Webrat.configure do |config| | |
+ config.mode = :rack_test | |
+end | |
+ | |
+class FakeApp | |
+ def call(env) | |
+ [200, { "Content-Length" => body.size.to_s }, body ] | |
+ end | |
+ | |
+ def body | |
+ "OK" | |
+ end | |
+end | |
describe "choose" do | |
+ include Rack::Test::Methods | |
+ include Webrat::Methods | |
+ | |
+ def app | |
+ @app ||= FakeApp.new | |
+ end | |
+ | |
+ def with_html(html) | |
+ app.stub!(:body => html) | |
+ visit "/" | |
+ end | |
+ | |
it "should fail if no radio buttons found" do | |
with_html <<-HTML | |
<html> | |
@@ -36,9 +68,10 @@ describe "choose" do | |
</form> | |
</html> | |
HTML | |
- webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "M"}) | |
+ | |
choose "Male" | |
click_button | |
+ last_request.GET.should == { "user" => { "gender" => "M" } } | |
end | |
it "should only submit last chosen value" do | |
@@ -53,10 +86,11 @@ describe "choose" do | |
</form> | |
</html> | |
HTML | |
- webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "M"}) | |
+ | |
choose "Female" | |
choose "Male" | |
click_button | |
+ last_request.GET.should == { "user" => { "gender" => "M" } } | |
end | |
it "should fail if the radio button is disabled" do | |
@@ -81,9 +115,10 @@ describe "choose" do | |
</form> | |
</html> | |
HTML | |
- webrat_session.should_receive(:post).with("/login", "first_option" => "on") | |
+ | |
choose "first_option" | |
click_button | |
+ last_request.POST.should == { "first_option" => "on" } | |
end | |
it "should result in the value on being posted if not specified and checked by default" do | |
@@ -95,8 +130,9 @@ describe "choose" do | |
</form> | |
</html> | |
HTML | |
- webrat_session.should_receive(:post).with("/login", "first_option" => "on") | |
+ | |
click_button | |
+ last_request.POST.should == { "first_option" => "on" } | |
end | |
it "should result in the value of the selected radio button being posted when a subsequent one is checked by default" do | |
@@ -111,8 +147,9 @@ describe "choose" do | |
</form> | |
</html> | |
HTML | |
- webrat_session.should_receive(:post).with("/login", "user" => {"gender" => "M"}) | |
+ | |
choose "Male" | |
click_button | |
+ last_request.POST.should == { "user" => { "gender" => "M" } } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment