From 3b8fc5551f22795f47b08ebad517e8b746e73f07 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 24 Nov 2008 19:59:27 -0500 Subject: [PATCH] RDoc tweaks --- README.txt => README.rdoc | 33 +++--- lib/webrat/core/configuration.rb | 4 +- lib/webrat/core/locators.rb | 4 +- lib/webrat/core/matchers/have_content.rb | 3 - lib/webrat/core/matchers/have_selector.rb | 2 - lib/webrat/core/matchers/have_xpath.rb | 2 - lib/webrat/core/mime.rb | 6 +- lib/webrat/core/nokogiri.rb | 6 +- lib/webrat/core/xml.rb | 8 +- lib/webrat/mechanize.rb | 4 +- lib/webrat/merb.rb | 4 +- lib/webrat/rails.rb | 4 +- lib/webrat/selenium.rb | 18 +-- lib/webrat/selenium/selenium_session.rb | 6 +- lib/webrat/test/run_spec.rb | 40 ------- lib/webrat/test/run_specs.rb | 127 ---------------------- spec/fakes/test_session.rb | 6 +- 17 files changed, 51 insertions(+), 226 deletions(-) rename README.txt => README.rdoc (81%) delete mode 100644 lib/webrat/test/run_spec.rb delete mode 100644 lib/webrat/test/run_specs.rb diff --git a/README.txt b/README.rdoc similarity index 81% rename from README.txt rename to README.rdoc index 9c64fc0..6ecaf3a 100644 --- a/README.txt +++ b/README.rdoc @@ -1,12 +1,11 @@ -=== Webrat += Webrat - Ruby Acceptance Testing for Web applications -- [Code on GitHub](http://github.com/brynary/webrat) -- [Tickets on Lighthouse](http://webrat.lighthouseapp.com/) +- {Code on GitHub}[http://github.com/brynary/webrat] +- {Tickets on Lighthouse}[http://webrat.lighthouseapp.com/] -=== Description +== Description -Webrat (_Ruby Acceptance Testing for Web applications_) -lets you quickly write robust and thorough acceptance tests for a Ruby +Webrat 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 in-browser testing solution without the associated performance hit (and 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 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 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. -=== Merb +== Merb To avoid losing sessions, you need this in environments/test.rb: -Merb::Config.use do |c| - c[:session_store] = 'memory' -end + Merb::Config.use do |c| + c[:session_store] = 'memory' + end -=== Install +== Install To install the latest release: @@ -78,13 +77,13 @@ In your stories/helper.rb: You could also unpack the gem into vendor/plugins. -=== Authors +== Authors -- Maintained by [Bryan Helmkamp](mailto:bryan@brynary.com) -- Original code written by [Seth Fitzsimmons](mailto:seth@mojodna.net) +- Maintained by {Bryan Helmkamp}[mailto:bryan@brynary.com] +- Original code written by {Seth Fitzsimmons}[mailto:seth@mojodna.net] - Many other contributors. See attributions in History.txt -=== License +== License Copyright (c) 2007 Bryan Helmkamp, Seth Fitzsimmons. See MIT-LICENSE.txt in this directory. diff --git a/lib/webrat/core/configuration.rb b/lib/webrat/core/configuration.rb index 3b216e7..5adad90 100755 --- a/lib/webrat/core/configuration.rb +++ b/lib/webrat/core/configuration.rb @@ -24,11 +24,11 @@ module Webrat self.parse_with_nokogiri = !Webrat.on_java? end - def parse_with_nokogiri? + def parse_with_nokogiri? #:nodoc: @parse_with_nokogiri ? true : false end - def open_error_files? + def open_error_files? #:nodoc: @open_error_files ? true : false end diff --git a/lib/webrat/core/locators.rb b/lib/webrat/core/locators.rb index d3ffb3e..3e4b96a 100644 --- a/lib/webrat/core/locators.rb +++ b/lib/webrat/core/locators.rb @@ -11,7 +11,7 @@ module Webrat end end - def field(*args) + def field(*args) # :nodoc: # This is the default locator strategy find_field_with_id(*args) || find_field_named(*args) || @@ -96,7 +96,7 @@ module Webrat 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) } if label label.for_id diff --git a/lib/webrat/core/matchers/have_content.rb b/lib/webrat/core/matchers/have_content.rb index 1383137..8344ed2 100644 --- a/lib/webrat/core/matchers/have_content.rb +++ b/lib/webrat/core/matchers/have_content.rb @@ -42,9 +42,6 @@ module Webrat # Matches the contents of an HTML document with # whatever string is supplied - # - # --- - # @api public def contain(content) HasContent.new(content) end diff --git a/lib/webrat/core/matchers/have_selector.rb b/lib/webrat/core/matchers/have_selector.rb index 605b0d8..3bf7112 100644 --- a/lib/webrat/core/matchers/have_selector.rb +++ b/lib/webrat/core/matchers/have_selector.rb @@ -28,8 +28,6 @@ module Webrat # # ==== Returns # HaveSelector:: A new have selector matcher. - # --- - # @api public def have_selector(expected, &block) HaveSelector.new(expected, &block) end diff --git a/lib/webrat/core/matchers/have_xpath.rb b/lib/webrat/core/matchers/have_xpath.rb index 907fde9..8d1825a 100644 --- a/lib/webrat/core/matchers/have_xpath.rb +++ b/lib/webrat/core/matchers/have_xpath.rb @@ -74,8 +74,6 @@ module Webrat # # ==== Returns # HaveXpath:: A new have xpath matcher. - # --- - # @api public def have_xpath(expected, &block) HaveXpath.new(expected, &block) end diff --git a/lib/webrat/core/mime.rb b/lib/webrat/core/mime.rb index 7851e4d..a8efe76 100644 --- a/lib/webrat/core/mime.rb +++ b/lib/webrat/core/mime.rb @@ -1,7 +1,7 @@ -module Webrat - module MIME +module Webrat #:nodoc: + 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) string_or_symbol else diff --git a/lib/webrat/core/nokogiri.rb b/lib/webrat/core/nokogiri.rb index 2b8e575..b40ba56 100644 --- a/lib/webrat/core/nokogiri.rb +++ b/lib/webrat/core/nokogiri.rb @@ -27,9 +27,9 @@ module Webrat end -module Nokogiri - module CSS - class XPathVisitor +module Nokogiri #:nodoc: + module CSS #:nodoc: + class XPathVisitor #:nodoc: def visit_pseudo_class_text(node) #:nodoc: "@type='text'" diff --git a/lib/webrat/core/xml.rb b/lib/webrat/core/xml.rb index e66fb69..626dc6c 100644 --- a/lib/webrat/core/xml.rb +++ b/lib/webrat/core/xml.rb @@ -1,7 +1,7 @@ -module Webrat - module XML +module Webrat #:nodoc: + module XML #:nodoc: - def self.document(stringlike) + def self.document(stringlike) #:nodoc: if Webrat.configuration.parse_with_nokogiri? Webrat.nokogiri_document(stringlike) else @@ -21,7 +21,7 @@ module Webrat end end - def self.css_search(element, *searches) + def self.css_search(element, *searches) #:nodoc: if Webrat.configuration.parse_with_nokogiri? element.css(*searches) else diff --git a/lib/webrat/mechanize.rb b/lib/webrat/mechanize.rb index bdd9a40..e87ec30 100644 --- a/lib/webrat/mechanize.rb +++ b/lib/webrat/mechanize.rb @@ -1,7 +1,7 @@ require "mechanize" -module Webrat - class MechanizeSession < Session +module Webrat #:nodoc: + class MechanizeSession < Session #:nodoc: attr_accessor :response alias :page :response diff --git a/lib/webrat/merb.rb b/lib/webrat/merb.rb index 277c81c..35258e9 100644 --- a/lib/webrat/merb.rb +++ b/lib/webrat/merb.rb @@ -52,8 +52,8 @@ module Webrat end end -module Merb - module Test +module Merb #:nodoc: + module Test #:nodoc: module RequestHelper #:nodoc: def request(uri, env = {}) @_webrat_session ||= Webrat::MerbSession.new diff --git a/lib/webrat/rails.rb b/lib/webrat/rails.rb index 34d4e4c..ec2c37e 100644 --- a/lib/webrat/rails.rb +++ b/lib/webrat/rails.rb @@ -69,8 +69,8 @@ module Webrat end end -module ActionController - module Integration +module ActionController #:nodoc: + module Integration #:nodoc: class Session #:nodoc: unless instance_methods.include?("put_via_redirect") require "webrat/rails/redirect_actions" diff --git a/lib/webrat/selenium.rb b/lib/webrat/selenium.rb index 4b95a01..fe61f34 100644 --- a/lib/webrat/selenium.rb +++ b/lib/webrat/selenium.rb @@ -7,37 +7,37 @@ Webrat.configuration.mode = :selenium module Webrat - def self.with_selenium_server + def self.with_selenium_server #:nodoc: start_selenium_server yield stop_selenium_server 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.jar_file = File.expand_path(__FILE__ + "../../../../vendor/selenium-server.jar") remote_control.start :background => true TCPSocket.wait_for_service :host => "0.0.0.0", :port => 4444 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.stop end - def self.start_app_server + def self.start_app_server #:nodoc: 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} &") TCPSocket.wait_for_service :host => "0.0.0.0", :port => 3001 end - def self.stop_app_server + def self.stop_app_server #:nodoc: pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid") system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}" end - module Selenium - module Rails + module Selenium #:nodoc: + module Rails #:nodoc: class World < ::ActionController::IntegrationTest def initialize #:nodoc: @@ -50,8 +50,8 @@ module Webrat end -module ::ActionController - module Integration +module ::ActionController #:nodoc: + module Integration #:nodoc: class Session #:nodoc: include Webrat::Methods end diff --git a/lib/webrat/selenium/selenium_session.rb b/lib/webrat/selenium/selenium_session.rb index 8fca94a..47b689d 100644 --- a/lib/webrat/selenium/selenium_session.rb +++ b/lib/webrat/selenium/selenium_session.rb @@ -134,7 +134,7 @@ module Webrat protected - def setup + def setup #:nodoc: silence_stream(STDOUT) do Webrat.start_selenium_server Webrat.start_app_server @@ -147,11 +147,11 @@ module Webrat teardown_at_exit end - def selenium + def selenium #:nodoc: browser end - def teardown_at_exit + def teardown_at_exit #:nodoc: at_exit do silence_stream(STDOUT) do $browser.stop diff --git a/lib/webrat/test/run_spec.rb b/lib/webrat/test/run_spec.rb deleted file mode 100644 index e7bd7c2..0000000 --- a/lib/webrat/test/run_spec.rb +++ /dev/null @@ -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"] diff --git a/lib/webrat/test/run_specs.rb b/lib/webrat/test/run_specs.rb deleted file mode 100644 index bfd1603..0000000 --- a/lib/webrat/test/run_specs.rb +++ /dev/null @@ -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 diff --git a/spec/fakes/test_session.rb b/spec/fakes/test_session.rb index 9f9cbdb..005e714 100644 --- a/spec/fakes/test_session.rb +++ b/spec/fakes/test_session.rb @@ -1,9 +1,9 @@ -module Webrat - def self.session_class +module Webrat #:nodoc: + def self.session_class #:nodoc: TestSession end - class TestSession < Session + class TestSession < Session #:nodoc: attr_accessor :response_body attr_writer :response_code