webrat 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. data/.gitignore +4 -1
  2. data/Gemfile +19 -0
  3. data/History.txt +29 -0
  4. data/Rakefile +27 -63
  5. data/Thorfile +117 -0
  6. data/lib/webrat.rb +11 -3
  7. data/lib/webrat/{mechanize.rb → adapters/mechanize.rb} +0 -0
  8. data/lib/webrat/adapters/merb.rb +11 -0
  9. data/lib/webrat/{rack.rb → adapters/rack.rb} +0 -0
  10. data/lib/webrat/{rails.rb → adapters/rails.rb} +2 -23
  11. data/lib/webrat/{sinatra.rb → adapters/sinatra.rb} +0 -2
  12. data/lib/webrat/core.rb +0 -1
  13. data/lib/webrat/core/configuration.rb +6 -16
  14. data/lib/webrat/core/elements/area.rb +2 -2
  15. data/lib/webrat/core/elements/element.rb +3 -3
  16. data/lib/webrat/core/elements/field.rb +106 -30
  17. data/lib/webrat/core/elements/form.rb +4 -4
  18. data/lib/webrat/core/elements/label.rb +4 -4
  19. data/lib/webrat/core/elements/link.rb +6 -6
  20. data/lib/webrat/core/elements/select_option.rb +15 -2
  21. data/lib/webrat/core/locators.rb +1 -1
  22. data/lib/webrat/core/locators/area_locator.rb +3 -3
  23. data/lib/webrat/core/locators/button_locator.rb +6 -6
  24. data/lib/webrat/core/locators/field_by_id_locator.rb +3 -3
  25. data/lib/webrat/core/locators/field_labeled_locator.rb +2 -2
  26. data/lib/webrat/core/locators/field_named_locator.rb +3 -3
  27. data/lib/webrat/core/locators/form_locator.rb +1 -1
  28. data/lib/webrat/core/locators/label_locator.rb +2 -2
  29. data/lib/webrat/core/locators/link_locator.rb +7 -7
  30. data/lib/webrat/core/locators/select_option_locator.rb +5 -5
  31. data/lib/webrat/core/logging.rb +4 -5
  32. data/lib/webrat/core/matchers/have_content.rb +2 -7
  33. data/lib/webrat/core/matchers/have_xpath.rb +3 -28
  34. data/lib/webrat/core/methods.rb +1 -0
  35. data/lib/webrat/core/scope.rb +17 -2
  36. data/lib/webrat/core/session.rb +2 -1
  37. data/lib/webrat/core/xml.rb +41 -84
  38. data/lib/webrat/integrations/merb.rb +10 -0
  39. data/lib/webrat/integrations/rails.rb +25 -0
  40. data/lib/webrat/integrations/rspec-rails.rb +11 -0
  41. data/lib/webrat/integrations/selenium.rb +11 -0
  42. data/lib/webrat/rspec-rails.rb +2 -10
  43. data/lib/webrat/selenium.rb +0 -10
  44. data/lib/webrat/selenium/application_servers.rb +1 -1
  45. data/lib/webrat/selenium/application_servers/external.rb +1 -1
  46. data/lib/webrat/selenium/location_strategy_javascript/label.js +29 -3
  47. data/lib/webrat/selenium/location_strategy_javascript/webrat.js +1 -0
  48. data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +24 -4
  49. data/lib/webrat/selenium/selenium_rc_server.rb +2 -2
  50. data/lib/webrat/selenium/selenium_session.rb +21 -2
  51. data/lib/webrat/selenium/silence_stream.rb +1 -1
  52. data/spec/integration/mechanize/spec/spec_helper.rb +3 -1
  53. data/spec/integration/rails/app/controllers/{application.rb → application_controller.rb} +0 -0
  54. data/spec/integration/rails/app/controllers/webrat_controller.rb +3 -0
  55. data/spec/integration/rails/app/views/buttons/show.html.erb +0 -2
  56. data/spec/integration/rails/app/views/webrat/buttons.html.erb +0 -2
  57. data/spec/integration/rails/app/views/webrat/within.html.erb +3 -0
  58. data/spec/integration/rails/config/environment.rb +1 -1
  59. data/spec/integration/rails/config/routes.rb +1 -0
  60. data/spec/integration/rails/test/integration/button_click_test.rb +12 -26
  61. data/spec/integration/rails/test/integration/fill_in_test.rb +1 -1
  62. data/spec/integration/rails/test/integration/link_click_test.rb +1 -1
  63. data/spec/integration/rails/test/integration/webrat_test.rb +35 -9
  64. data/spec/integration/rails/test/test_helper.rb +1 -0
  65. data/spec/private/core/configuration_spec.rb +2 -31
  66. data/spec/private/core/field_spec.rb +14 -16
  67. data/spec/private/mechanize/mechanize_adapter_spec.rb +0 -2
  68. data/spec/private/nokogiri_spec.rb +2 -2
  69. data/spec/private/rails/rails_adapter_spec.rb +0 -27
  70. data/spec/public/basic_auth_spec.rb +13 -2
  71. data/spec/public/click_button_spec.rb +10 -12
  72. data/spec/public/click_link_spec.rb +21 -0
  73. data/spec/public/fill_in_spec.rb +15 -0
  74. data/spec/public/matchers/have_selector_spec.rb +4 -0
  75. data/spec/public/select_spec.rb +232 -26
  76. data/spec/spec_helper.rb +2 -0
  77. data/webrat.gemspec +305 -313
  78. metadata +21 -25
  79. data/VERSION +0 -1
  80. data/lib/webrat/core/xml/hpricot.rb +0 -19
  81. data/lib/webrat/core/xml/nokogiri.rb +0 -76
  82. data/lib/webrat/core/xml/rexml.rb +0 -24
  83. data/lib/webrat/merb_adapter.rb +0 -82
  84. data/lib/webrat/merb_multipart_support.rb +0 -27
  85. data/spec/private/core/logging_spec.rb +0 -10
  86. data/spec/private/merb/attaches_file_spec.rb +0 -93
  87. data/spec/private/merb/merb_adapter_spec.rb +0 -61
data/.gitignore CHANGED
@@ -12,4 +12,7 @@ log
12
12
  results
13
13
  test_apps
14
14
  *.tmproj
15
- *.log
15
+ *.log
16
+ *.pid
17
+ bin
18
+ vendor/gems
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ clear_sources
2
+ source 'http://gemcutter.org'
3
+
4
+ disable_system_gems
5
+
6
+ gem "git", "1.2.5"
7
+ gem "rake", "0.8.7"
8
+ gem "rspec", "1.2.9"
9
+ gem "diff-lcs", "1.1.2"
10
+ gem "rack", "1.0.1"
11
+ gem "nokogiri", "1.4.0"
12
+ gem "merb-core", "1.0.15"
13
+ gem "selenium-client", "1.2.17"
14
+ gem "mechanize", "0.9.3"
15
+ gem "rails", "2.3.4"
16
+ gem "launchy", "0.3.3"
17
+ gem "rack-test", "0.5.2"
18
+ gem "sinatra", "0.9.4"
19
+ gem "mongrel", "1.1.5"
@@ -1,3 +1,32 @@
1
+ == 0.6.0 / 2009-11-28
2
+
3
+ REMOVED: Support for Hpricot + REXML as an alternative to Nokogiri.
4
+
5
+ Hpricot and REXML were difficult to work with, REXML is terribly slow,
6
+ and Nokogiri is recommended even by the author of Hpricot (_why). Now
7
+ that Nokogiri works on JRuby, Webrat is going to use it as its sole
8
+ XML backend.
9
+
10
+ CHANGED: Due to a reorganization, if you're currently requiring "webrat/rspec-rails",
11
+ please change your code to require "webrat/integrations/rspec-rails"
12
+
13
+ * Minor enhancements
14
+
15
+ * Support Rails 2.3.4 JavaScript form authenticity tokens in simulated mode (Jonathan Weiss)
16
+ * When a timeout occurs in wait_for, include the HTML from Selenium in the exception
17
+ * Update the Merb support to be based directly on Rack (Simon Rozet)
18
+ * Support multiple select fields (Kieran P)
19
+ * When locating select options, always match against text, not HTML
20
+
21
+ * Bug fixes
22
+
23
+ * Remove newlines from HTTP Basic authentication credentials (Michael Klett)
24
+ * Require nokogiri form rspec-rails.rb (David Chelimsky)
25
+ * Fix logger issue when running inside Cucumber (Damian Janowski)
26
+ * Fix various issues related to submitting values with HTML entities (Kieran P)
27
+ * Call #to_i on the :count option in matchers (Michael Christenson II)
28
+ * Fix bug where multiline param values were getting truncated
29
+
1
30
  == 0.5.3 / 2009-08-27
2
31
 
3
32
  * Minor enhancements
data/Rakefile CHANGED
@@ -1,58 +1,26 @@
1
- begin
2
- require 'jeweler'
3
-
4
- Jeweler::Tasks.new do |s|
5
- s.name = "webrat"
6
- s.author = "Bryan Helmkamp"
7
- s.email = "bryan" + "@" + "brynary.com"
8
- s.homepage = "http://github.com/brynary/webrat"
9
- s.summary = "Ruby Acceptance Testing for Web applications"
10
- s.description = <<-EOS.strip
11
- Webrat lets you quickly write expressive and robust acceptance tests
12
- for a Ruby web application. It supports simulating a browser inside
13
- a Ruby process to avoid the performance hit and browser dependency of
14
- Selenium or Watir, but the same API can also be used to drive real
15
- Selenium tests when necessary (eg. for testing AJAX interactions).
16
- Most Ruby web frameworks and testing frameworks are supported.
17
- EOS
18
-
19
- s.rubyforge_project = "webrat"
20
- s.extra_rdoc_files = %w[README.rdoc MIT-LICENSE.txt History.txt]
21
-
22
- # Dependencies
23
- s.add_dependency "nokogiri", ">= 1.2.0"
24
- s.add_dependency "rack", ">= 1.0"
25
-
26
- # TODO: Add development dependencies
27
- end
1
+ require "rubygems"
28
2
 
29
- Jeweler::RubyforgeTasks.new
3
+ begin
4
+ require 'spec/rake/spectask'
30
5
  rescue LoadError
31
- puts "Jeweler not available. Install it with: gem install jeweler"
32
- end
33
-
34
- # require 'spec'
35
- require 'spec/rake/spectask'
36
- require 'spec/rake/verify_rcov'
37
-
38
- desc "Run API and Core specs"
39
- Spec::Rake::SpecTask.new do |t|
40
- t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
41
- t.spec_files = FileList['spec/public/**/*_spec.rb'] + FileList['spec/private/**/*_spec.rb']
42
- end
43
-
44
- desc "Run all specs in spec directory with RCov"
45
- Spec::Rake::SpecTask.new(:rcov) do |t|
46
- t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
47
- t.spec_files = FileList['spec/public/**/*_spec.rb'] + FileList['spec/private/**/*_spec.rb']
48
- t.rcov = true
49
- t.rcov_opts = lambda do
50
- IO.readlines(File.dirname(__FILE__) + "/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
6
+ desc "Run specs"
7
+ task(:spec) { $stderr.puts '`gem install rspec` to run specs' }
8
+ else
9
+ desc "Run API and Core specs"
10
+ Spec::Rake::SpecTask.new do |t|
11
+ t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
12
+ t.spec_files = FileList['spec/public/**/*_spec.rb'] + FileList['spec/private/**/*_spec.rb']
51
13
  end
52
- end
53
14
 
54
- RCov::VerifyTask.new(:verify_rcov => :rcov) do |t|
55
- t.threshold = 96.2 # Make sure you have rcov 0.7 or higher!
15
+ desc "Run all specs in spec directory with RCov"
16
+ Spec::Rake::SpecTask.new(:rcov) do |t|
17
+ t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
18
+ t.spec_files = FileList['spec/public/**/*_spec.rb'] + FileList['spec/private/**/*_spec.rb']
19
+ t.rcov = true
20
+ t.rcov_opts = lambda do
21
+ IO.readlines(File.dirname(__FILE__) + "/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
22
+ end
23
+ end
56
24
  end
57
25
 
58
26
  desc "Run everything against multiruby"
@@ -107,18 +75,18 @@ task :spec_deps do
107
75
  end
108
76
  end
109
77
 
110
- task :prepare do
111
- system "ln -s ../../../../.. ./spec/integration/rails/vendor/plugins/webrat"
112
- end
113
-
114
78
  namespace :spec do
115
79
  desc "Run the integration specs"
116
- task :integration => ["integration:rails", "integration:merb", "integration:sinatra", "integration:rack", "integration:mechanize"]
80
+ task :integration => [
81
+ "integration:rack",
82
+ "integration:sinatra",
83
+ "integration:merb",
84
+ "integration:mechanize",
85
+ "integration:rails:webrat",
86
+ "integration:rails:selenium",
87
+ ]
117
88
 
118
89
  namespace :integration do
119
- desc "Run the Rails integration specs"
120
- task :rails => ['rails:webrat'] #,'rails:selenium'] currently not running selenium as it doesn't pass.
121
-
122
90
  namespace :rails do
123
91
  task :selenium do
124
92
  Dir.chdir "spec/integration/rails" do
@@ -174,8 +142,4 @@ task :whitespace do
174
142
  sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
175
143
  end
176
144
 
177
- if defined?(Jeweler)
178
- task :spec => :check_dependencies
179
- end
180
-
181
145
  task :default => :spec
@@ -0,0 +1,117 @@
1
+ module GemHelpers
2
+
3
+ def generate_gemspec
4
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "lib")))
5
+ require "webrat"
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "webrat"
9
+ s.version = Webrat::VERSION
10
+ s.author = "Bryan Helmkamp"
11
+ s.email = "bryan@brynary.com"
12
+ s.homepage = "http://github.com/brynary/webrat"
13
+ s.summary = "Ruby Acceptance Testing for Web applications"
14
+ s.description = <<-EOS.strip
15
+ Webrat lets you quickly write expressive and robust acceptance tests
16
+ for a Ruby web application. It supports simulating a browser inside
17
+ a Ruby process to avoid the performance hit and browser dependency of
18
+ Selenium or Watir, but the same API can also be used to drive real
19
+ Selenium tests when necessary (eg. for testing AJAX interactions).
20
+ Most Ruby web frameworks and testing frameworks are supported.
21
+ EOS
22
+ s.rubyforge_project = "webrat"
23
+
24
+ require "git"
25
+ repo = Git.open(".")
26
+
27
+ s.files = normalize_files(repo.ls_files.keys - repo.lib.ignored_files)
28
+ s.test_files = normalize_files(Dir['spec/**/*.rb'] - repo.lib.ignored_files)
29
+
30
+ s.has_rdoc = true
31
+ s.extra_rdoc_files = %w[README.rdoc MIT-LICENSE.txt History.txt]
32
+
33
+ s.add_dependency "nokogiri", ">= 1.2.0"
34
+ s.add_dependency "rack", ">= 1.0"
35
+ end
36
+ end
37
+
38
+ def normalize_files(array)
39
+ # only keep files, no directories, and sort
40
+ array.select do |path|
41
+ File.file?(path)
42
+ end.sort
43
+ end
44
+
45
+ # Adds extra space when outputting an array. This helps create better version
46
+ # control diffs, because otherwise it is all on the same line.
47
+ def prettyify_array(gemspec_ruby, array_name)
48
+ gemspec_ruby.gsub(/s\.#{array_name.to_s} = \[.+?\]/) do |match|
49
+ leadin, files = match[0..-2].split("[")
50
+ leadin + "[\n #{files.split(",").join(",\n ")}\n ]"
51
+ end
52
+ end
53
+
54
+ def read_gemspec
55
+ @read_gemspec ||= eval(File.read("webrat.gemspec"))
56
+ end
57
+
58
+ def sh(command)
59
+ puts command
60
+ system command
61
+ end
62
+ end
63
+
64
+ class Default < Thor
65
+ include GemHelpers
66
+
67
+ desc "gemspec", "Regenerate webrat.gemspec"
68
+ def gemspec
69
+ File.open("webrat.gemspec", "w") do |file|
70
+ gemspec_ruby = generate_gemspec.to_ruby
71
+ gemspec_ruby = prettyify_array(gemspec_ruby, :files)
72
+ gemspec_ruby = prettyify_array(gemspec_ruby, :test_files)
73
+ gemspec_ruby = prettyify_array(gemspec_ruby, :extra_rdoc_files)
74
+
75
+ file.write gemspec_ruby
76
+ end
77
+
78
+ puts "Wrote gemspec to webrat.gemspec"
79
+ read_gemspec.validate
80
+ end
81
+
82
+ desc "build", "Build a webrat gem"
83
+ def build
84
+ sh "gem build webrat.gemspec"
85
+ FileUtils.mkdir_p "pkg"
86
+ FileUtils.mv read_gemspec.file_name, "pkg"
87
+ end
88
+
89
+ desc "install", "Install the latest built gem"
90
+ def install
91
+ sh "gem install --local pkg/#{read_gemspec.file_name}"
92
+ end
93
+
94
+ desc "release", "Release the current branch to GitHub and Gemcutter"
95
+ def release
96
+ gemspec
97
+ build
98
+ Release.new.tag
99
+ Release.new.gem
100
+ end
101
+ end
102
+
103
+ class Release < Thor
104
+ include GemHelpers
105
+
106
+ desc "tag", "Tag the gem on the origin server"
107
+ def tag
108
+ release_tag = "v#{read_gemspec.version}"
109
+ sh "git tag -a #{release_tag} -m 'Tagging #{release_tag}'"
110
+ sh "git push origin #{release_tag}"
111
+ end
112
+
113
+ desc "gem", "Push the gem to Gemcutter"
114
+ def gem
115
+ sh "gem push pkg/#{read_gemspec.file_name}"
116
+ end
117
+ end
@@ -1,10 +1,18 @@
1
+ require "rack"
2
+ require "nokogiri"
3
+
1
4
  module Webrat
5
+ VERSION = "0.6.0"
6
+
7
+ autoload :MechanizeAdapter, "webrat/adapters/mechanize"
8
+ autoload :MerbAdapter, "webrat/adapters/merb"
9
+ autoload :RackAdapter, "webrat/adapters/rack"
10
+ autoload :RailsAdapter, "webrat/adapters/rails"
11
+ autoload :SinatraAdapter, "webrat/adapters/sinatra"
12
+
2
13
  # The common base class for all exceptions raised by Webrat.
3
14
  class WebratError < StandardError
4
15
  end
5
16
  end
6
17
 
7
- require "rack"
8
- require "nokogiri"
9
- require "webrat/core/xml/nokogiri"
10
18
  require "webrat/core"
@@ -0,0 +1,11 @@
1
+ require "webrat/integrations/merb"
2
+
3
+ module Webrat
4
+ class MerbAdapter < RackAdapter #:nodoc:
5
+ def initialize(context=nil)
6
+ app = context.respond_to?(:app) ?
7
+ context.app : Merb::Rack::Application.new
8
+ super(Rack::Test::Session.new(Rack::MockSession.new(app, "www.example.com")))
9
+ end
10
+ end
11
+ end
File without changes
@@ -1,4 +1,5 @@
1
- require "webrat"
1
+ require "webrat/integrations/rails"
2
+ require "action_controller/record_identifier"
2
3
 
3
4
  module Webrat
4
5
  class RailsAdapter #:nodoc:
@@ -10,21 +11,6 @@ module Webrat
10
11
  @integration_session = session
11
12
  end
12
13
 
13
- # The Rails version of within supports passing in a model and Webrat
14
- # will apply a scope based on Rails' dom_id for that model.
15
- #
16
- # Example:
17
- # within User.last do
18
- # click_link "Delete"
19
- # end
20
- def within(selector_or_object, &block)
21
- if selector_or_object.is_a?(String)
22
- super
23
- else
24
- super('#' + dom_id(selector_or_object), &block)
25
- end
26
- end
27
-
28
14
  def doc_root
29
15
  File.expand_path(File.join(RAILS_ROOT, 'public'))
30
16
  end
@@ -93,10 +79,3 @@ module Webrat
93
79
  end
94
80
  end
95
81
  end
96
-
97
- module ActionController #:nodoc:
98
- IntegrationTest.class_eval do
99
- include Webrat::Methods
100
- include Webrat::Matchers
101
- end
102
- end
@@ -1,5 +1,3 @@
1
- require "webrat/rack"
2
-
3
1
  module Webrat
4
2
  class SinatraAdapter < RackAdapter
5
3
  def initialize(context)
@@ -1,6 +1,5 @@
1
1
  require "webrat/core/configuration"
2
2
  require "webrat/core/xml"
3
- require "webrat/core/xml/nokogiri"
4
3
  require "webrat/core/logging"
5
4
  require "webrat/core/elements/form"
6
5
  require "webrat/core/scope"
@@ -16,13 +16,10 @@ module Webrat
16
16
  # Webrat can be configured using the Webrat.configure method. For example:
17
17
  #
18
18
  # Webrat.configure do |config|
19
- # config.parse_with_nokogiri = false
19
+ # config.mode = :sinatra
20
20
  # end
21
21
  class Configuration
22
22
 
23
- # Should XHTML be parsed with Nokogiri? Defaults to true, except on JRuby. When false, Hpricot and REXML are used
24
- attr_writer :parse_with_nokogiri
25
-
26
23
  # Webrat's mode, set automatically when requiring webrat/rails, webrat/merb, etc.
27
24
  attr_reader :mode # :nodoc:
28
25
 
@@ -63,7 +60,6 @@ module Webrat
63
60
 
64
61
  def initialize # :nodoc:
65
62
  self.open_error_files = true
66
- self.parse_with_nokogiri = true
67
63
  self.application_environment = :test
68
64
  self.application_port = 3001
69
65
  self.application_address = 'localhost'
@@ -74,10 +70,6 @@ module Webrat
74
70
  self.selenium_browser_startup_timeout = 5
75
71
  end
76
72
 
77
- def parse_with_nokogiri? #:nodoc:
78
- @parse_with_nokogiri ? true : false
79
- end
80
-
81
73
  def open_error_files? #:nodoc:
82
74
  @open_error_files ? true : false
83
75
  end
@@ -87,13 +79,11 @@ module Webrat
87
79
  def mode=(mode)
88
80
  @mode = mode.to_sym
89
81
 
90
- # This is a temporary hack to support backwards compatibility
91
- # with Merb 1.0.8 until it's updated to use the new Webrat.configure
92
- # syntax
93
- if @mode == :merb
94
- require("webrat/merb_adapter")
95
- else
96
- require("webrat/#{mode}")
82
+ begin
83
+ require("webrat/integrations/#{mode}")
84
+ rescue LoadError
85
+ # Only some modes have integration code that needs to
86
+ # be loaded, so this is OK
97
87
  end
98
88
  end
99
89
 
@@ -4,7 +4,7 @@ module Webrat
4
4
  class Area < Element #:nodoc:
5
5
 
6
6
  def self.xpath_search
7
- ".//area"
7
+ [".//area"]
8
8
  end
9
9
 
10
10
  def click(method = nil, options = {})
@@ -14,7 +14,7 @@ module Webrat
14
14
  protected
15
15
 
16
16
  def href
17
- Webrat::XML.attribute(@element, "href")
17
+ @element["href"]
18
18
  end
19
19
 
20
20
  def absolute_href