webrat 0.6.0 → 0.7.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.
@@ -1,3 +1,20 @@
1
+ == 0.7.0 / 2010-01-17
2
+
3
+ * Major enhancements
4
+
5
+ * Upgrade bundled Selenium server JAR to 2.0a1 (Henry Poydar and Jake Scruggs)
6
+
7
+ * Minor enhancements
8
+
9
+ * Save and open page directory specified via configuration, defaults to tmp dir otherwise current dir (Noah Davis)
10
+
11
+ * Bug fixes
12
+
13
+ * Added missing dependency "rack-test" to gemspec (LH #339) (Noah Davis)
14
+ * Removed save_and_open_page's rewriting of static asset paths before saving (was not actually working) (Noah Davis)
15
+ * Make "should contain" ignore extra whitespace when doing string comparisons (Noah Davis)
16
+ * Make selenium matchers handle negative match more consistently with positive match (Luke Melia)
17
+
1
18
  == 0.6.0 / 2009-11-28
2
19
 
3
20
  REMOVED: Support for Hpricot + REXML as an alternative to Nokogiri.
data/Thorfile CHANGED
@@ -32,6 +32,7 @@ Most Ruby web frameworks and testing frameworks are supported.
32
32
 
33
33
  s.add_dependency "nokogiri", ">= 1.2.0"
34
34
  s.add_dependency "rack", ">= 1.0"
35
+ s.add_dependency "rack-test", ">= 0.5.3"
35
36
  end
36
37
  end
37
38
 
@@ -2,7 +2,7 @@ require "rack"
2
2
  require "nokogiri"
3
3
 
4
4
  module Webrat
5
- VERSION = "0.6.0"
5
+ VERSION = "0.7.0"
6
6
 
7
7
  autoload :MechanizeAdapter, "webrat/adapters/mechanize"
8
8
  autoload :MerbAdapter, "webrat/adapters/merb"
@@ -11,14 +11,6 @@ module Webrat
11
11
  @integration_session = session
12
12
  end
13
13
 
14
- def doc_root
15
- File.expand_path(File.join(RAILS_ROOT, 'public'))
16
- end
17
-
18
- def saved_page_dir
19
- File.expand_path(File.join(RAILS_ROOT, "tmp"))
20
- end
21
-
22
14
  def get(url, data, headers = nil)
23
15
  do_request(:get, url, data, headers)
24
16
  end
@@ -1,4 +1,5 @@
1
1
  require "webrat/core_extensions/deprecate"
2
+ require "pathname"
2
3
 
3
4
  module Webrat
4
5
 
@@ -26,7 +27,10 @@ module Webrat
26
27
  # Save and open pages with error status codes (500-599) in a browser? Defualts to true.
27
28
  attr_writer :open_error_files
28
29
 
29
- # Which rails environment should the selenium tests be run in? Defaults to selenium.
30
+ # Save and open page storage directory, defaults to "tmp" under current directory if exists, otherwise current directory
31
+ attr_accessor :saved_pages_dir
32
+
33
+ # Which rails environment should the selenium tests be run in? Defaults to test.
30
34
  attr_accessor :application_environment
31
35
  webrat_deprecate :selenium_environment, :application_environment
32
36
  webrat_deprecate :selenium_environment=, :application_environment=
@@ -68,6 +72,9 @@ module Webrat
68
72
  self.infinite_redirect_limit = 10
69
73
  self.selenium_browser_key = '*firefox'
70
74
  self.selenium_browser_startup_timeout = 5
75
+
76
+ tmp_dir = Pathname.new(Dir.pwd).join("tmp")
77
+ self.saved_pages_dir = tmp_dir.exist? ? tmp_dir : Dir.pwd
71
78
  end
72
79
 
73
80
  def open_error_files? #:nodoc:
@@ -12,7 +12,7 @@ module Webrat
12
12
 
13
13
  case @content
14
14
  when String
15
- @element.include?(@content)
15
+ @element.gsub(/\s+/, ' ').include?(@content)
16
16
  when Regexp
17
17
  @element.match(@content)
18
18
  end
@@ -6,12 +6,12 @@ module Webrat
6
6
  # Example:
7
7
  # save_and_open_page
8
8
  def save_and_open_page
9
- return unless File.exist?(saved_page_dir)
9
+ return unless File.exist?(Webrat.configuration.saved_pages_dir)
10
10
 
11
- filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.html"
11
+ filename = "#{Webrat.configuration.saved_pages_dir}/webrat-#{Time.now.to_i}.html"
12
12
 
13
13
  File.open(filename, "w") do |f|
14
- f.write rewrite_css_and_image_references(response_body)
14
+ f.write response_body
15
15
  end
16
16
 
17
17
  open_in_browser(filename)
@@ -24,25 +24,5 @@ module Webrat
24
24
  warn "Sorry, you need to install launchy to open pages: `gem install launchy`"
25
25
  end
26
26
 
27
- def rewrite_css_and_image_references(response_html) # :nodoc:
28
- return response_html unless doc_root
29
- response_html.gsub(/("|')\/(stylesheets|images)/, '\1' + doc_root + '/\2')
30
- end
31
-
32
- def saved_page_dir #:nodoc:
33
- File.expand_path(".")
34
- end
35
-
36
- def doc_root #:nodoc:
37
- nil
38
- end
39
-
40
- private
41
-
42
- # accessor for testing
43
- def ruby_platform
44
- RUBY_PLATFORM
45
- end
46
-
47
27
  end
48
28
  end
@@ -92,10 +92,6 @@ For example:
92
92
  page
93
93
  end
94
94
 
95
- def doc_root #:nodoc:
96
- nil
97
- end
98
-
99
95
  def header(key, value)
100
96
  @custom_headers[key] = value
101
97
  end
@@ -7,29 +7,33 @@ module Webrat
7
7
  end
8
8
 
9
9
  def matches?(response)
10
- if @content.is_a?(Regexp)
11
- text_finder = "regexp:#{@content.source}"
12
- else
13
- text_finder = @content
10
+ response.session.wait_for do
11
+ response.selenium.is_text_present(text_finder)
14
12
  end
13
+ rescue Webrat::TimeoutError => e
14
+ @error_message = e.message
15
+ false
16
+ end
15
17
 
18
+ def does_not_match?(response)
16
19
  response.session.wait_for do
17
- response.selenium.is_text_present(text_finder)
20
+ !response.selenium.is_text_present(text_finder)
18
21
  end
19
- rescue Webrat::TimeoutError
20
- false
22
+ rescue Webrat::TimeoutError => e
23
+ @error_message = e.message
24
+ false
21
25
  end
22
26
 
23
27
  # ==== Returns
24
28
  # String:: The failure message.
25
29
  def failure_message
26
- "expected the following element's content to #{content_message}:\n#{@element}"
30
+ "expected the response to #{content_message}:\n#{@error_message}"
27
31
  end
28
32
 
29
33
  # ==== Returns
30
34
  # String:: The failure message to be displayed in negative matches.
31
35
  def negative_failure_message
32
- "expected the following element's content to not #{content_message}:\n#{@element}"
36
+ "expected the response to not #{content_message}"
33
37
  end
34
38
 
35
39
  def content_message
@@ -40,6 +44,14 @@ module Webrat
40
44
  "match #{@content.inspect}"
41
45
  end
42
46
  end
47
+
48
+ def text_finder
49
+ if @content.is_a?(Regexp)
50
+ "regexp:#{@content.source}"
51
+ else
52
+ @content
53
+ end
54
+ end
43
55
  end
44
56
 
45
57
  # Matches the contents of an HTML document with
@@ -52,7 +64,7 @@ module Webrat
52
64
  # the supplied string or regexp
53
65
  def assert_contain(content)
54
66
  hc = HasContent.new(content)
55
- assert hc.matches?(response), hc.failure_message
67
+ assert hc.matches?(response), hc.failure_message
56
68
  end
57
69
 
58
70
  # Asserts that the body of the response
@@ -14,6 +14,14 @@ module Webrat
14
14
  false
15
15
  end
16
16
 
17
+ def does_not_match?(response)
18
+ response.session.wait_for do
19
+ !response.selenium.is_element_present("css=#{@expected}")
20
+ end
21
+ rescue Webrat::TimeoutError
22
+ false
23
+ end
24
+
17
25
  # ==== Returns
18
26
  # String:: The failure message.
19
27
  def failure_message
@@ -14,6 +14,14 @@ module Webrat
14
14
  false
15
15
  end
16
16
 
17
+ def does_not_match?(response)
18
+ response.session.wait_for do
19
+ !response.selenium.is_element_present("xpath=#{@expected}")
20
+ end
21
+ rescue Webrat::TimeoutError
22
+ false
23
+ end
24
+
17
25
  # ==== Returns
18
26
  # String:: The failure message.
19
27
  def failure_message
@@ -61,7 +61,7 @@ module Webrat
61
61
  TCPSocket.wait_for_service_with_timeout \
62
62
  :host => (Webrat.configuration.selenium_server_address || "0.0.0.0"),
63
63
  :port => Webrat.configuration.selenium_server_port,
64
- :timeout => 15 # seconds
64
+ :timeout => 45 # seconds
65
65
  end
66
66
  end
67
67
 
@@ -195,9 +195,9 @@ EOS
195
195
 
196
196
 
197
197
  def save_and_open_screengrab
198
- return unless File.exist?(saved_page_dir)
198
+ return unless File.exist?(Webrat.configuration.saved_pages_dir)
199
199
 
200
- filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.png"
200
+ filename = "#{Webrat.configuration.saved_pages_dir}/webrat-#{Time.now.to_i}.png"
201
201
 
202
202
  if $browser.chrome_backend?
203
203
  $browser.capture_entire_page_screenshot(filename, '')
@@ -10,10 +10,6 @@ module Webrat #:nodoc:
10
10
  def initialize(*args)
11
11
  end
12
12
 
13
- def doc_root
14
- File.expand_path(File.join(".", "public"))
15
- end
16
-
17
13
  def response
18
14
  @response ||= Object.new
19
15
  end
@@ -2,11 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
2
 
3
3
  describe Webrat::Session do
4
4
 
5
- it "should not have a doc_root" do
6
- session = Webrat::Session.new
7
- session.doc_root.should be_nil
8
- end
9
-
10
5
  it "should expose the current_dom" do
11
6
  session = Webrat::Session.new
12
7
 
@@ -76,11 +76,4 @@ describe Webrat::RailsAdapter do
76
76
  end
77
77
  end
78
78
 
79
- it "should provide a saved_page_dir" do
80
- Webrat::RailsAdapter.new(mock("integration session")).should respond_to(:saved_page_dir)
81
- end
82
-
83
- it "should provide a doc_root" do
84
- Webrat::RailsAdapter.new(mock("integration session")).should respond_to(:doc_root)
85
- end
86
79
  end
@@ -3,21 +3,6 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
3
3
  describe "contain" do
4
4
  include Webrat::Matchers
5
5
 
6
- before(:each) do
7
- @body = <<-HTML
8
- <div id='main'>
9
- <div class='inner'>hello, world!</div>
10
- <h2>Welcome "Bryan"</h2>
11
- <h3>Welcome 'Bryan'</h3>
12
- <h4>Welcome 'Bryan"</h4>
13
- <ul>
14
- <li>First</li>
15
- <li>Second</li>
16
- </ul>
17
- </div>
18
- HTML
19
- end
20
-
21
6
  before(:each) do
22
7
  @body = <<-EOF
23
8
  <div id='main'>
@@ -34,6 +19,14 @@ describe "contain" do
34
19
  it "should call element#matches? when the argument is a regular expression" do
35
20
  @body.should contain(/hello, world/)
36
21
  end
22
+
23
+ it "should treat newlines as spaces" do
24
+ "<div>it takes\ndifferent strokes</div>".should contain("it takes different strokes")
25
+ end
26
+
27
+ it "should multiple spaces as a single space" do
28
+ "<div>it takes different strokes</div>".should contain("it takes different strokes")
29
+ end
37
30
  end
38
31
 
39
32
  describe "asserts for contains," do
@@ -22,30 +22,13 @@ describe "save_and_open_page" do
22
22
  Launchy::Browser.stub!(:run)
23
23
 
24
24
  @file_handle = mock("file handle")
25
- File.stub!(:open).with(filename, 'w').and_yield(@file_handle)
25
+ File.stub!(:open).and_yield(@file_handle)
26
26
  @file_handle.stub!(:write)
27
27
  end
28
28
 
29
- it "should rewrite css rules" do
30
- @file_handle.should_receive(:write) do |html|
31
- html.should =~ %r|"#{webrat_session.doc_root}/stylesheets/foo.css"|s
32
- end
33
-
34
- save_and_open_page
35
- end
36
-
37
- it "should rewrite image paths with double quotes" do
38
- @file_handle.should_receive(:write) do |html|
39
- html.should =~ %r|"#{webrat_session.doc_root}/images/bar.png"|s
40
- end
41
-
42
- save_and_open_page
43
- end
44
-
45
- it "should rewrite image paths with single quotes" do
46
- @file_handle.should_receive(:write) do |html|
47
- html.should =~ %r|'#{webrat_session.doc_root}/images/foo.png'|s
48
- end
29
+ it "should save pages to the directory configured" do
30
+ Webrat.configuration.stub!(:saved_pages_dir => "path/to/dir")
31
+ File.should_receive(:open).with("path/to/dir/webrat-1234.html", "w").and_yield(@file_handle)
49
32
 
50
33
  save_and_open_page
51
34
  end
@@ -63,8 +46,4 @@ describe "save_and_open_page" do
63
46
  end.should_not raise_error
64
47
  end
65
48
 
66
- def filename
67
- File.expand_path("./webrat-#{Time.now}.html")
68
- end
69
-
70
49
  end
Binary file
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{webrat}
5
- s.version = "0.6.0"
5
+ s.version = "0.7.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Bryan Helmkamp"]
9
- s.date = %q{2009-11-28}
9
+ s.date = %q{2010-01-17}
10
10
  s.description = %q{Webrat lets you quickly write expressive and robust acceptance tests
11
11
  for a Ruby web application. It supports simulating a browser inside
12
12
  a Ruby process to avoid the performance hit and browser dependency of
@@ -337,12 +337,15 @@ Most Ruby web frameworks and testing frameworks are supported.}
337
337
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
338
338
  s.add_runtime_dependency(%q<nokogiri>, [">= 1.2.0"])
339
339
  s.add_runtime_dependency(%q<rack>, [">= 1.0"])
340
+ s.add_runtime_dependency(%q<rack-test>, [">= 0.5.3"])
340
341
  else
341
342
  s.add_dependency(%q<nokogiri>, [">= 1.2.0"])
342
343
  s.add_dependency(%q<rack>, [">= 1.0"])
344
+ s.add_dependency(%q<rack-test>, [">= 0.5.3"])
343
345
  end
344
346
  else
345
347
  s.add_dependency(%q<nokogiri>, [">= 1.2.0"])
346
348
  s.add_dependency(%q<rack>, [">= 1.0"])
349
+ s.add_dependency(%q<rack-test>, [">= 0.5.3"])
347
350
  end
348
351
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webrat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Helmkamp
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-28 00:00:00 -05:00
12
+ date: 2010-01-17 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: "1.0"
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rack-test
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.5.3
44
+ version:
35
45
  description: |-
36
46
  Webrat lets you quickly write expressive and robust acceptance tests
37
47
  for a Ruby web application. It supports simulating a browser inside