RDoc tweaks

This commit is contained in:
Bryan Helmkamp 2008-11-24 19:59:27 -05:00
parent 5502948417
commit 3b8fc5551f
17 changed files with 51 additions and 226 deletions

View File

@ -1,12 +1,11 @@
=== Webrat = Webrat - Ruby Acceptance Testing for Web applications
- [Code on GitHub](http://github.com/brynary/webrat) - {Code on GitHub}[http://github.com/brynary/webrat]
- [Tickets on Lighthouse](http://webrat.lighthouseapp.com/) - {Tickets on Lighthouse}[http://webrat.lighthouseapp.com/]
=== Description == Description
Webrat (_Ruby Acceptance Testing for Web applications_) Webrat lets you quickly write robust and thorough acceptance tests for a Ruby
lets you quickly write robust and thorough acceptance tests for a Ruby
web application. By leveraging the DOM, it can run tests similarly to an web application. By leveraging the DOM, it can run tests similarly to an
in-browser testing solution without the associated performance hit (and in-browser testing solution without the associated performance hit (and
browser dependency). The result is tests that are less fragile and more browser dependency). The result is tests that are less fragile and more
@ -19,9 +18,9 @@ that may make it a requirement for your project. If JavaScript is not central
to your application, Webrat is a simpler, effective solution that will let you to your application, Webrat is a simpler, effective solution that will let you
run your tests much faster and more frequently. run your tests much faster and more frequently.
Initial development was sponsored by [EastMedia](http://www.eastmedia.com). Initial development was sponsored by EastMedia[http://www.eastmedia.com].
=== Synopsis == Synopsis
def test_sign_up def test_sign_up
visit "/" visit "/"
@ -59,14 +58,14 @@ tests to break unnecessarily as your application evolves:
A test written with Webrat can handle these changes to these without any modifications. A test written with Webrat can handle these changes to these without any modifications.
=== Merb == Merb
To avoid losing sessions, you need this in environments/test.rb: To avoid losing sessions, you need this in environments/test.rb:
Merb::Config.use do |c| Merb::Config.use do |c|
c[:session_store] = 'memory' c[:session_store] = 'memory'
end end
=== Install == Install
To install the latest release: To install the latest release:
@ -78,13 +77,13 @@ In your stories/helper.rb:
You could also unpack the gem into vendor/plugins. You could also unpack the gem into vendor/plugins.
=== Authors == Authors
- Maintained by [Bryan Helmkamp](mailto:bryan@brynary.com) - Maintained by {Bryan Helmkamp}[mailto:bryan@brynary.com]
- Original code written by [Seth Fitzsimmons](mailto:seth@mojodna.net) - Original code written by {Seth Fitzsimmons}[mailto:seth@mojodna.net]
- Many other contributors. See attributions in History.txt - Many other contributors. See attributions in History.txt
=== License == License
Copyright (c) 2007 Bryan Helmkamp, Seth Fitzsimmons. Copyright (c) 2007 Bryan Helmkamp, Seth Fitzsimmons.
See MIT-LICENSE.txt in this directory. See MIT-LICENSE.txt in this directory.

View File

@ -24,11 +24,11 @@ module Webrat
self.parse_with_nokogiri = !Webrat.on_java? self.parse_with_nokogiri = !Webrat.on_java?
end end
def parse_with_nokogiri? def parse_with_nokogiri? #:nodoc:
@parse_with_nokogiri ? true : false @parse_with_nokogiri ? true : false
end end
def open_error_files? def open_error_files? #:nodoc:
@open_error_files ? true : false @open_error_files ? true : false
end end

View File

@ -11,7 +11,7 @@ module Webrat
end end
end end
def field(*args) def field(*args) # :nodoc:
# This is the default locator strategy # This is the default locator strategy
find_field_with_id(*args) || find_field_with_id(*args) ||
find_field_named(*args) || find_field_named(*args) ||
@ -96,7 +96,7 @@ module Webrat
end end
end end
def find_field_id_for_label(label_text) def find_field_id_for_label(label_text) #:nodoc:
label = forms.detect_mapped { |form| form.label_matching(label_text) } label = forms.detect_mapped { |form| form.label_matching(label_text) }
if label if label
label.for_id label.for_id

View File

@ -42,9 +42,6 @@ module Webrat
# Matches the contents of an HTML document with # Matches the contents of an HTML document with
# whatever string is supplied # whatever string is supplied
#
# ---
# @api public
def contain(content) def contain(content)
HasContent.new(content) HasContent.new(content)
end end

View File

@ -28,8 +28,6 @@ module Webrat
# #
# ==== Returns # ==== Returns
# HaveSelector:: A new have selector matcher. # HaveSelector:: A new have selector matcher.
# ---
# @api public
def have_selector(expected, &block) def have_selector(expected, &block)
HaveSelector.new(expected, &block) HaveSelector.new(expected, &block)
end end

View File

@ -74,8 +74,6 @@ module Webrat
# #
# ==== Returns # ==== Returns
# HaveXpath:: A new have xpath matcher. # HaveXpath:: A new have xpath matcher.
# ---
# @api public
def have_xpath(expected, &block) def have_xpath(expected, &block)
HaveXpath.new(expected, &block) HaveXpath.new(expected, &block)
end end

View File

@ -1,7 +1,7 @@
module Webrat module Webrat #:nodoc:
module MIME module MIME #:nodoc:
def self.mime_type(string_or_symbol) def self.mime_type(string_or_symbol) #:nodoc:
if string_or_symbol.is_a?(String) if string_or_symbol.is_a?(String)
string_or_symbol string_or_symbol
else else

View File

@ -27,9 +27,9 @@ module Webrat
end end
module Nokogiri module Nokogiri #:nodoc:
module CSS module CSS #:nodoc:
class XPathVisitor class XPathVisitor #:nodoc:
def visit_pseudo_class_text(node) #:nodoc: def visit_pseudo_class_text(node) #:nodoc:
"@type='text'" "@type='text'"

View File

@ -1,7 +1,7 @@
module Webrat module Webrat #:nodoc:
module XML module XML #:nodoc:
def self.document(stringlike) def self.document(stringlike) #:nodoc:
if Webrat.configuration.parse_with_nokogiri? if Webrat.configuration.parse_with_nokogiri?
Webrat.nokogiri_document(stringlike) Webrat.nokogiri_document(stringlike)
else else
@ -21,7 +21,7 @@ module Webrat
end end
end end
def self.css_search(element, *searches) def self.css_search(element, *searches) #:nodoc:
if Webrat.configuration.parse_with_nokogiri? if Webrat.configuration.parse_with_nokogiri?
element.css(*searches) element.css(*searches)
else else

View File

@ -1,7 +1,7 @@
require "mechanize" require "mechanize"
module Webrat module Webrat #:nodoc:
class MechanizeSession < Session class MechanizeSession < Session #:nodoc:
attr_accessor :response attr_accessor :response
alias :page :response alias :page :response

View File

@ -52,8 +52,8 @@ module Webrat
end end
end end
module Merb module Merb #:nodoc:
module Test module Test #:nodoc:
module RequestHelper #:nodoc: module RequestHelper #:nodoc:
def request(uri, env = {}) def request(uri, env = {})
@_webrat_session ||= Webrat::MerbSession.new @_webrat_session ||= Webrat::MerbSession.new

View File

@ -69,8 +69,8 @@ module Webrat
end end
end end
module ActionController module ActionController #:nodoc:
module Integration module Integration #:nodoc:
class Session #:nodoc: class Session #:nodoc:
unless instance_methods.include?("put_via_redirect") unless instance_methods.include?("put_via_redirect")
require "webrat/rails/redirect_actions" require "webrat/rails/redirect_actions"

View File

@ -7,37 +7,37 @@ Webrat.configuration.mode = :selenium
module Webrat module Webrat
def self.with_selenium_server def self.with_selenium_server #:nodoc:
start_selenium_server start_selenium_server
yield yield
stop_selenium_server stop_selenium_server
end end
def self.start_selenium_server def self.start_selenium_server #:nodoc:
remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", 4444, 5) remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", 4444, 5)
remote_control.jar_file = File.expand_path(__FILE__ + "../../../../vendor/selenium-server.jar") remote_control.jar_file = File.expand_path(__FILE__ + "../../../../vendor/selenium-server.jar")
remote_control.start :background => true remote_control.start :background => true
TCPSocket.wait_for_service :host => "0.0.0.0", :port => 4444 TCPSocket.wait_for_service :host => "0.0.0.0", :port => 4444
end end
def self.stop_selenium_server def self.stop_selenium_server #:nodoc:
remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", 4444, 5) remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", 4444, 5)
remote_control.stop remote_control.stop
end end
def self.start_app_server def self.start_app_server #:nodoc:
pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid") pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid")
system("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=3001 --environment=selenium --pid #{pid_file} &") system("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=3001 --environment=selenium --pid #{pid_file} &")
TCPSocket.wait_for_service :host => "0.0.0.0", :port => 3001 TCPSocket.wait_for_service :host => "0.0.0.0", :port => 3001
end end
def self.stop_app_server def self.stop_app_server #:nodoc:
pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid") pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid")
system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}" system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
end end
module Selenium module Selenium #:nodoc:
module Rails module Rails #:nodoc:
class World < ::ActionController::IntegrationTest class World < ::ActionController::IntegrationTest
def initialize #:nodoc: def initialize #:nodoc:
@ -50,8 +50,8 @@ module Webrat
end end
module ::ActionController module ::ActionController #:nodoc:
module Integration module Integration #:nodoc:
class Session #:nodoc: class Session #:nodoc:
include Webrat::Methods include Webrat::Methods
end end

View File

@ -134,7 +134,7 @@ module Webrat
protected protected
def setup def setup #:nodoc:
silence_stream(STDOUT) do silence_stream(STDOUT) do
Webrat.start_selenium_server Webrat.start_selenium_server
Webrat.start_app_server Webrat.start_app_server
@ -147,11 +147,11 @@ module Webrat
teardown_at_exit teardown_at_exit
end end
def selenium def selenium #:nodoc:
browser browser
end end
def teardown_at_exit def teardown_at_exit #:nodoc:
at_exit do at_exit do
silence_stream(STDOUT) do silence_stream(STDOUT) do
$browser.stop $browser.stop

View File

@ -1,40 +0,0 @@
require "stringio"
require 'rubygems'
require 'spec'
require 'spec/runner/formatter/specdoc_formatter'
module Spec
module Runner
module Formatter
class BaseTextFormatter
def dump_failure(counter, failure)
output = @options.error_stream
output.puts
output.puts "#{counter.to_s})"
output.puts colourise("#{failure.header}\n#{failure.exception.message}", failure)
output.puts format_backtrace(failure.exception.backtrace)
output.flush
end
end
end
end
end
def run_spec(spec, base_dir)
$VERBOSE = nil
err, out = StringIO.new, StringIO.new
def out.tty?() true end
options = Spec::Runner::OptionParser.parse(%W(#{spec} -fs --color), err, out)
options.filename_pattern = File.expand_path(spec)
failure = ! Spec::Runner::CommandLine.run(options)
File.open(File.join(base_dir, "results", "#{File.basename(spec)}_out"), "w") do |file|
file.puts out.string
end
File.open(File.join(base_dir, "results", "#{File.basename(spec)}_err"), "w") do |file|
file.puts err.string
end
exit!(failure ? -1 : 0)
end
run_spec(ARGV[0], File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))) if ENV["NOW"]

View File

@ -1,127 +0,0 @@
require 'rubygems'
require 'benchmark'
require 'spec'
require 'spec/runner/formatter/base_text_formatter'
require 'spec/spec_helper.rb'
# Load this stuff so it only has to be loaded once for the entire suite
require 'spec/mocks'
require 'spec/mocks/extensions'
require 'spec/runner/formatter/specdoc_formatter'
require 'base64'
require 'nkf'
require 'kconv'
require 'rack'
require 'fileutils'
begin
require 'json'
rescue
require 'json/pure'
end
Merb::Dispatcher
module Merb
class Counter
attr_accessor :time
def initialize
@examples, @failures, @errors, @pending, @total_time = 0, 0, 0, 0, 0
@err = ""
@mutex = Mutex.new
end
def failed?
@failures > 0
end
def add(spec, out, err)
@mutex.synchronize do
puts
puts "Running #{spec}."
STDOUT.puts out
STDOUT.flush
match = out.match(/(\d+) examples?, (\d+) failures?(?:, (\d+) errors?)?(?:, (\d+) pending?)?/m)
time = out.match(/Finished in (\d+\.\d+) seconds/)
@total_time += time[1].to_f if time
if match
e, f, errors, pending = match[1..-1]
@examples += e.to_i
@failures += f.to_i
@errors += errors.to_i
@pending += pending.to_i
end
unless err.chomp.empty?
@err << err.chomp << "\n"
end
end
end
def report
i = 0
@err.gsub!(/^\d*\)\s*/) do
"#{i += 1})\n"
end
puts @err
puts
if @failures != 0 || @errors != 0
print "\e[31m" # Red
elsif @pending != 0
print "\e[33m" # Yellow
else
print "\e[32m" # Green
end
puts "#{@examples} examples, #{@failures} failures, #{@errors} errors, #{@pending} pending, #{sprintf("suite run in %3.3f seconds", @time.real)}"
# TODO: we need to report pending examples all together
puts "\e[0m"
end
end
end
require File.dirname(__FILE__) / "run_spec"
# Runs specs in all files matching the file pattern.
#
def run_specs(globs)
require "optparse"
require "spec"
globs = globs.is_a?(Array) ? globs : [globs]
forking = (ENV["FORK"] ? ENV["FORK"] == "1" : Merb.forking_environment?)
base_dir = File.expand_path(File.dirname(__FILE__) / ".." / ".." / "..")
counter = Merb::Counter.new
forks = 0
failure = false
FileUtils.rm_rf(File.join(base_dir, "results"))
FileUtils.mkdir_p(File.join(base_dir, "results"))
time = Benchmark.measure do
files = {}
globs.each do |glob|
Dir[glob].each do |spec|
if forking
Kernel.fork do
run_spec(spec, base_dir)
end
Process.wait
else
`NOW=1 #{Gem.ruby} #{File.dirname(__FILE__) / "run_spec.rb"} \"#{spec}\"`
end
out = File.read(File.join(base_dir, "results", "#{File.basename(spec)}_out"))
err = File.read(File.join(base_dir, "results", "#{File.basename(spec)}_err"))
counter.add(spec, out, err)
end
end
end
Process.waitall
counter.time = time
counter.report
FileUtils.rm_rf(File.join(base_dir, "results"))
exit!(counter.failed? ? -1 : 0)
end

View File

@ -1,9 +1,9 @@
module Webrat module Webrat #:nodoc:
def self.session_class def self.session_class #:nodoc:
TestSession TestSession
end end
class TestSession < Session class TestSession < Session #:nodoc:
attr_accessor :response_body attr_accessor :response_body
attr_writer :response_code attr_writer :response_code