Skip to content

Commit

Permalink
Add some missing spec coverage. Bump coverage theshold
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Aug 11, 2008
1 parent 87b8e71 commit 399a385
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions lib/webrat/core/form.rb
Expand Up @@ -19,12 +19,12 @@ def find_field(id_or_name_or_label, *field_types)

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

Expand Down
2 changes: 1 addition & 1 deletion lib/webrat/core/logging.rb
Expand Up @@ -3,7 +3,7 @@ module Logging

def debug_log(message) # :nodoc:
return unless logger
logger.debug
logger.debug(message)
end

def logger # :nodoc:
Expand Down
30 changes: 30 additions & 0 deletions spec/api/clicks_link_spec.rb
Expand Up @@ -131,6 +131,26 @@
@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
<a href="/posts/1" onclick="var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
f.method = 'POST';
f.action = this.href;
var m = document.createElement('input');
m.setAttribute('type', 'hidden');
m.setAttribute('name', '_method');
f.appendChild(m);
f.submit();
return false;">Link</a>
EOS

lambda {
@session.clicks_link "Link"
}.should raise_error
end

it "should assert valid response" do
@session.response_body = <<-EOS
<a href="/page">Link text</a>
Expand All @@ -139,6 +159,16 @@
lambda { @session.clicks_link "Link text" }.should raise_error
end

it "should fail is the link doesn't exist" do
@session.response_body = <<-EOS
<a href="/page">Link text</a>
EOS

lambda {
@session.clicks_link "Missing link"
}.should raise_error
end

it "should not be case sensitive" do
@session.response_body = <<-EOS
<a href="/page">Link text</a>
Expand Down
13 changes: 13 additions & 0 deletions spec/api/selects_spec.rb
Expand Up @@ -134,6 +134,19 @@
@session.selects(/jan/i)
@session.clicks_button
end

it "should fail if no option matching the regexp exists" do
@session.response_body = <<-EOS
<form method="post" action="/login">
<select name="month"><option>January</option></select>
<input type="submit" />
</form>
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
Expand Down
12 changes: 12 additions & 0 deletions 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
33 changes: 33 additions & 0 deletions 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
"<html></html>"
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

0 comments on commit 399a385

Please sign in to comment.