From 399a3852a108f3cdbafaa6864a73636b752a30f4 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 11 Aug 2008 00:29:21 -0400 Subject: [PATCH] Add some missing spec coverage. Bump coverage theshold --- Rakefile | 2 +- lib/webrat/core/form.rb | 4 ++-- lib/webrat/core/logging.rb | 2 +- spec/api/clicks_link_spec.rb | 30 +++++++++++++++++++++++++++++ spec/api/selects_spec.rb | 13 +++++++++++++ spec/webrat/core/logging_spec.rb | 12 ++++++++++++ spec/webrat/core/session_spec.rb | 33 ++++++++++++++++++++++++++++++++ 7 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 spec/webrat/core/logging_spec.rb create mode 100644 spec/webrat/core/session_spec.rb diff --git a/Rakefile b/Rakefile index e3d475d..dd71f72 100644 --- a/Rakefile +++ b/Rakefile @@ -56,7 +56,7 @@ end require 'spec/rake/verify_rcov' RCov::VerifyTask.new(:verify_rcov => :rcov) do |t| - t.threshold = 97.5 # Make sure you have rcov 0.7 or higher! + t.threshold = 99.9 # Make sure you have rcov 0.7 or higher! end remove_task "default" diff --git a/lib/webrat/core/form.rb b/lib/webrat/core/form.rb index 9be4ece..60a5c07 100644 --- a/lib/webrat/core/form.rb +++ b/lib/webrat/core/form.rb @@ -19,12 +19,12 @@ module Webrat def find_select_option(option_text) select_fields = fields_by_type([SelectField]) - + select_fields.each do |select_field| result = select_field.find_option(option_text) return result if result end - + nil end diff --git a/lib/webrat/core/logging.rb b/lib/webrat/core/logging.rb index 08e9870..e2be0c4 100644 --- a/lib/webrat/core/logging.rb +++ b/lib/webrat/core/logging.rb @@ -3,7 +3,7 @@ module Webrat def debug_log(message) # :nodoc: return unless logger - logger.debug + logger.debug(message) end def logger # :nodoc: diff --git a/spec/api/clicks_link_spec.rb b/spec/api/clicks_link_spec.rb index c77d019..8909962 100644 --- a/spec/api/clicks_link_spec.rb +++ b/spec/api/clicks_link_spec.rb @@ -131,6 +131,26 @@ describe "clicks_link" do @session.clicks_link "Put" end + it "should fail if the javascript link doesn't have a value for the _method input" do + @session.response_body = <<-EOS + Link + EOS + + lambda { + @session.clicks_link "Link" + }.should raise_error + end + it "should assert valid response" do @session.response_body = <<-EOS Link text @@ -139,6 +159,16 @@ describe "clicks_link" do lambda { @session.clicks_link "Link text" }.should raise_error end + it "should fail is the link doesn't exist" do + @session.response_body = <<-EOS + Link text + EOS + + lambda { + @session.clicks_link "Missing link" + }.should raise_error + end + it "should not be case sensitive" do @session.response_body = <<-EOS Link text diff --git a/spec/api/selects_spec.rb b/spec/api/selects_spec.rb index ce1fc5b..21aeb4e 100644 --- a/spec/api/selects_spec.rb +++ b/spec/api/selects_spec.rb @@ -134,6 +134,19 @@ describe "selects" do @session.selects(/jan/i) @session.clicks_button end + + it "should fail if no option matching the regexp exists" do + @session.response_body = <<-EOS +
+ + +
+ EOS + + lambda { + @session.selects(/feb/i) + }.should raise_error + end it "should find option by regexp in list specified by label" do @session.response_body = <<-EOS diff --git a/spec/webrat/core/logging_spec.rb b/spec/webrat/core/logging_spec.rb new file mode 100644 index 0000000..73f5bbc --- /dev/null +++ b/spec/webrat/core/logging_spec.rb @@ -0,0 +1,12 @@ +require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") + +describe Webrat::Logging do + include Webrat::Logging + + it "should log to RAILS_DEFAULT_LOGGER" do + logger = mock("logger") + RAILS_DEFAULT_LOGGER = logger + logger.should_receive(:debug).with("Testing") + debug_log "Testing" + end +end \ No newline at end of file diff --git a/spec/webrat/core/session_spec.rb b/spec/webrat/core/session_spec.rb new file mode 100644 index 0000000..376e4b7 --- /dev/null +++ b/spec/webrat/core/session_spec.rb @@ -0,0 +1,33 @@ +require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") + +describe Webrat::Session do + + it "should not have a doc_root" do + session = Webrat::Session.new + session.doc_root.should be_nil + end + + it "should expose the current_dom" do + session = Webrat::Session.new + + def session.response_body + "" + end + + session.current_dom.should be_an_instance_of(Hpricot::Doc) + end + + it "should open the page in the browser" do + session = Webrat::Session.new + session.should_receive(:`).with("open path") + session.open_in_browser("path") + end + + it "should provide a current_page for backwards compatibility" do + session = Webrat::Session.new + current_page = session.current_page + current_page.should_not be_nil + current_page.should respond_to(:url) + end + +end \ No newline at end of file