spec_ui 0.2.3 → 0.2.4

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.
@@ -14,9 +14,10 @@ lib/spec/ui/version.rb
14
14
  lib/spec/ui/watir.rb
15
15
  lib/spec/ui/watir/browser.rb
16
16
  lib/spec/ui/watir/matchers.rb
17
+ lib/spec/ui/watir/watir_behaviour.rb
17
18
  examples/selenium/Rakefile
18
19
  examples/selenium/README.txt
19
- examples/selenium/spec/google/find_rspecs_homepage_spec.rb
20
+ examples/selenium/spec/selenium/find_rspecs_homepage_spec.rb
20
21
  examples/selenium/spec/spec_helper.rb
21
22
  examples/watir/Rakefile
22
23
  examples/watir/README.txt
@@ -1,17 +1,57 @@
1
- # You don't need to tweak the $LOAD_PATH if you have RSpec and Spec::Ui installed as gems
2
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../../rspec/lib')
1
+ # You don't need to tweak the $LOAD_PATH if you have RSpec installed as a gem
2
+ $LOAD_PATH.unshift('../../../rspec/lib')
3
3
 
4
4
  require 'rubygems'
5
5
  require 'spec/rake/spectask'
6
6
 
7
7
  desc "Run Selenium Specs"
8
8
  Spec::Rake::SpecTask.new('spec:selenium') do |t|
9
- t.spec_files = FileList['spec/google/**/*.rb']
10
- # This line is not necessary if you have RSpec and Spec::Ui installed as gems
11
- t.ruby_opts = ["-I#{File.dirname(__FILE__) + '/../../lib'}"]
9
+ t.spec_files = FileList['spec/selenium/**/*.rb']
10
+ # This line is not necessary if you have Spec::Ui installed as a gem
11
+ t.libs = ["../../lib"]
12
12
  t.spec_opts = [
13
+ '--color', '--diff',
13
14
  '--require', 'rubygems,spec/ui',
14
15
  '--format', 'Spec::Ui::ScreenshotFormatter:spec_report.html',
15
16
  '--format', 'progress'
16
17
  ]
17
18
  end
19
+
20
+ # IMPORTANT: If you use the master/slave mode you really ought to
21
+ # run everything on different machines.
22
+
23
+ desc "Run Selenium Specs as Spec::Distributed slave"
24
+ Spec::Rake::SpecTask.new('spec:selenium:slave') do |t|
25
+ t.spec_files = FileList['spec/selenium/**/*.rb']
26
+ # This line is not necessary if you have Spec::Ui and Spec::Distributed installed as gems
27
+ t.libs = ["../../lib", "../../../spec_distributed/lib"]
28
+ t.spec_opts = lambda do
29
+ url = ENV['DRB_URL']
30
+ raise "You must pass DRB_URL=druby://localhost:8991 (for example) on the command line" if url.nil?
31
+ [
32
+ '--color', '--diff',
33
+ '--require', 'rubygems,spec/ui,spec/distributed',
34
+ '--format', 'Spec::Ui::SlaveScreenshotFormatter:spec_report.html',
35
+ '--format', 'progress',
36
+ '--runner', "Spec::Distributed::SlaveRunner:#{url}"
37
+ ]
38
+ end
39
+ end
40
+
41
+ desc "Run Selenium Specs as Spec::Distributed master"
42
+ Spec::Rake::SpecTask.new('spec:selenium:master') do |t|
43
+ t.spec_files = FileList['spec/selenium/**/*.rb']
44
+ # This line is not necessary if you have Spec::Ui and Spec::Distributed installed as gems
45
+ t.libs = ["../../lib", "../../../spec_distributed/lib"]
46
+ t.spec_opts = lambda do
47
+ urls = ENV['DRB_URLS']
48
+ raise "You must pass DRB_URLS=druby://localhost:8991,druby://localhost:8991 (for example) on the command line" if urls.nil?
49
+ [
50
+ '--color', '--diff',
51
+ '--require', 'rubygems,spec/ui,spec/distributed',
52
+ '--format', 'Spec::Ui::MasterScreenshotFormatter:spec_report.html',
53
+ '--format', 'progress',
54
+ '--runner', "Spec::Distributed::MasterRunner:#{urls}"
55
+ ]
56
+ end
57
+ end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- describe "Google's search page" do
3
+ describe "Google's search page I" do
4
4
 
5
5
  before(:each) do
6
6
  # The @browser is initialised in spec_helper.rb
@@ -13,6 +13,15 @@ describe "Google's search page" do
13
13
  @browser.is_text_present("rspec.rubyforge.org").should be_true
14
14
  end
15
15
 
16
+ end
17
+
18
+ describe "Google's search page II" do
19
+
20
+ before(:each) do
21
+ # The @browser is initialised in spec_helper.rb
22
+ @browser.open('http://www.google.no')
23
+ end
24
+
16
25
  it "should find rspec's home page when I search for 'better than fudge' (will probably fail)" do
17
26
  @browser.type "name=q", "better than fudge"
18
27
  @browser.click_and_wait "name=btnG"
@@ -25,4 +34,4 @@ describe "Google's search page" do
25
34
  @browser.is_text_present("Ali G").should be_false
26
35
  end
27
36
 
28
- end
37
+ end
@@ -16,7 +16,7 @@ Spec::Runner.configure do |config|
16
16
  end
17
17
 
18
18
  config.after(:each) do
19
- Spec::Ui::ScreenshotFormatter.take_screenshot_of(@browser)
19
+ Spec::Ui::ScreenshotFormatter.instance.take_screenshot_of(@browser)
20
20
  end
21
21
 
22
22
  config.after(:all) do
@@ -1,5 +1,5 @@
1
- # You don't need to tweak the $LOAD_PATH if you have RSpec and Spec::Ui installed as gems
2
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../../rspec/lib')
1
+ # You don't need to tweak the $LOAD_PATH if you have RSpec installed as a gem
2
+ $LOAD_PATH.unshift('../../../rspec/lib')
3
3
 
4
4
  require 'rubygems'
5
5
  require 'spec/rake/spectask'
@@ -7,11 +7,51 @@ require 'spec/rake/spectask'
7
7
  desc "Run Watir Specs"
8
8
  Spec::Rake::SpecTask.new('spec:watir') do |t|
9
9
  t.spec_files = FileList['spec/watir/**/*.rb']
10
- # This line is not necessary if you have RSpec and Spec::Ui installed as gems
11
- t.ruby_opts = ["-I#{File.dirname(__FILE__) + '/../../lib'}"]
10
+ # This line is not necessary if you have Spec::Ui installed as a gem
11
+ t.libs = ["../../lib"]
12
12
  t.spec_opts = [
13
+ '--color', '--diff',
13
14
  '--require', 'rubygems,spec/ui',
14
15
  '--format', 'Spec::Ui::ScreenshotFormatter:spec_report.html',
15
16
  '--format', 'progress'
16
17
  ]
17
18
  end
19
+
20
+ # IMPORTANT: If you use the master/slave mode you really ought to
21
+ # run everything on different machines.
22
+
23
+ desc "Run Watir Specs as Spec::Distributed slave"
24
+ Spec::Rake::SpecTask.new('spec:watir:slave') do |t|
25
+ t.spec_files = FileList['spec/watir/**/*.rb']
26
+ # This line is not necessary if you have Spec::Ui and Spec::Distributed installed as gems
27
+ t.libs = ["../../lib", "../../../spec_distributed/lib"]
28
+ t.spec_opts = lambda do
29
+ url = ENV['DRB_URL']
30
+ raise "You must pass DRB_URL=druby://localhost:8991 (for example) on the command line" if url.nil?
31
+ [
32
+ '--color', '--diff',
33
+ '--require', 'rubygems,spec/ui,spec/distributed',
34
+ '--format', 'Spec::Ui::SlaveScreenshotFormatter:spec_report.html',
35
+ '--format', 'progress',
36
+ '--runner', "Spec::Distributed::SlaveRunner:#{url}"
37
+ ]
38
+ end
39
+ end
40
+
41
+ desc "Run Watir Specs as Spec::Distributed master"
42
+ Spec::Rake::SpecTask.new('spec:watir:master') do |t|
43
+ t.spec_files = FileList['spec/watir/**/*.rb']
44
+ # This line is not necessary if you have Spec::Ui and Spec::Distributed installed as gems
45
+ t.libs = ["../../lib", "../../../spec_distributed/lib"]
46
+ t.spec_opts = lambda do
47
+ urls = ENV['DRB_URLS']
48
+ raise "You must pass DRB_URLS=druby://localhost:8991,druby://localhost:8991 (for example) on the command line" if urls.nil?
49
+ [
50
+ '--color', '--diff',
51
+ '--require', 'rubygems,spec/ui,spec/distributed',
52
+ '--format', 'Spec::Ui::MasterScreenshotFormatter:spec_report.html',
53
+ '--format', 'progress',
54
+ '--runner', "Spec::Distributed::MasterRunner:#{urls}"
55
+ ]
56
+ end
57
+ end
@@ -11,12 +11,12 @@ Spec::Runner.configure do |config|
11
11
  config.before(:all) do
12
12
  @browser = Watir::Browser.new
13
13
  end
14
-
14
+
15
15
  config.after(:each) do
16
- Spec::Ui::ScreenshotFormatter.take_screenshot_of(@browser)
16
+ Spec::Ui::ScreenshotFormatter.instance.take_screenshot_of(@browser)
17
17
  end
18
18
 
19
19
  config.after(:all) do
20
- @browser.kill! rescue nil
20
+ @browser.kill!
21
21
  end
22
- end
22
+ end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- describe "Google's search page" do
3
+ describe "Google's search page I" do
4
4
  before(:each) do
5
5
  # The @browser is initialised in spec_helper.rb
6
6
  @browser.goto('http://www.google.com')
@@ -9,7 +9,14 @@ describe "Google's search page" do
9
9
  it "should find rspec's home page when I search for rspec" do
10
10
  @browser.text_field(:name, "q").set("rspec")
11
11
  @browser.button(:name, "btnG").click
12
- @browser.should have_link(:url, "http://rspec.rubyforge.org/")
12
+ @browser.should have_link(:url, "http://rspec.rubyforge.org/index.html")
13
+ end
14
+ end
15
+
16
+ describe "Google's search page II" do
17
+ before(:each) do
18
+ # The @browser is initialised in spec_helper.rb
19
+ @browser.goto('http://www.google.com')
13
20
  end
14
21
 
15
22
  it "should find rspec's home page when I search for 'better than fudge' (this is supposed to fail)" do
@@ -25,4 +32,4 @@ describe "Google's search page" do
25
32
  end
26
33
 
27
34
  it "should do something we haven't done yet"
28
- end
35
+ end
@@ -1,113 +1,162 @@
1
- require 'tempfile'
2
- require 'base64'
3
- require 'cgi'
4
- require 'spec/ui/screenshot_saver'
5
-
6
- module Spec
7
- module Ui
8
- class ScreenshotFormatter < Spec::Runner::Formatter::HtmlFormatter
9
- class << self
10
- include ScreenshotSaver
11
- attr_reader :html
12
-
13
- # Takes screenshot and snapshot of the +browser+'s html.
14
- # This method calls #screenshot! so that method should not be called
15
- # when this method is used.
16
- # This method *must* be called in an after(:each) block.
17
- def take_screenshot_of(browser)
18
- screenshot
19
- @html = browser.html
20
- end
21
-
22
- # Takes a screenshot of the current window. Use this method when
23
- # you don't have a browser object.
24
- def screenshot
25
- @png_path = Tempfile.new("spec:ui").path
26
- save_screenshot(png_path)
27
- end
28
-
29
- def png_path
30
- raise "Screenshot not taken. You must call #{self.name}.screenshot or #{self.name}.take_screenshot_of(@browser) from after(:each)" if @png_path.nil?
31
- @png_path
32
- end
33
-
34
- # Resets the screenshot and html. Do not call this method from your specs.
35
- def reset!
36
- @png_path = nil
37
- @html = nil
38
- end
39
- end
40
-
41
- def global_scripts
42
- super + <<-EOF
43
- function showImage(e) {
44
- w = window.open();
45
- w.location = e.childNodes[0].src
46
- }
47
-
48
- // Lifted from Ruby RDoc
49
- function toggleSource( id ) {
50
- var elem
51
- var link
52
-
53
- if( document.getElementById )
54
- {
55
- elem = document.getElementById( id )
56
- link = document.getElementById( "l_" + id )
57
- }
58
- else if ( document.all )
59
- {
60
- elem = eval( "document.all." + id )
61
- link = eval( "document.all.l_" + id )
62
- }
63
- else
64
- return false;
65
-
66
- if( elem.style.display == "block" )
67
- {
68
- elem.style.display = "none"
69
- link.innerHTML = "show source"
70
- }
71
- else
72
- {
73
- elem.style.display = "block"
74
- link.innerHTML = "hide source"
75
- }
76
- }
77
- EOF
78
- end
79
-
80
- def global_styles
81
- super + <<-EOF
82
- div.rspec-report textarea {
83
- width: 100%;
84
- }
85
-
86
- div.rspec-report div.dyn-source {
87
- background:#FFFFEE none repeat scroll 0%;
88
- border:1px dotted black;
89
- color:#000000;
90
- display:none;
91
- margin:0.5em 2em;
92
- padding:0.5em;
93
- }
94
- EOF
95
- end
96
-
97
- def extra_failure_content(failure)
98
- result = super(failure)
99
- # Add embedded image to the report.
100
- img_data = Base64.encode64(File.open(self.class.png_path, "rb").read)
101
- result += " <div><a href=\"#\" onclick=\"showImage(this)\"><img width=\"25%\" height=\"25%\" src=\"data:image/png;base64,#{img_data}\" /></a></div>\n"
102
- if self.class.html
103
- escaped_html = CGI::escapeHTML(self.class.html)
104
- source_id = "#{current_example_number}_source"
105
- result += " <div>[<a id=\"l_#{source_id}\" href=\"javascript:toggleSource('#{source_id}')\">show source</a>]</div>\n"
106
- result += " <div id=\"#{source_id}\" class=\"dyn-source\"><textarea rows=\"20\">#{escaped_html}</textarea></div>\n"
107
- end
108
- self.class.reset!
109
- result
110
- end
111
- end
112
- end
113
- end
1
+ require 'spec/ui/screenshot_saver'
2
+ require 'stringio'
3
+
4
+ module Spec
5
+ module Ui
6
+ class ScreenshotFormatter < Spec::Runner::Formatter::HtmlFormatter
7
+ class << self
8
+ attr_accessor :instance
9
+ end
10
+
11
+ include ScreenshotSaver
12
+
13
+ def initialize(where, out=where)
14
+ super(out)
15
+ if where.is_a?(String)
16
+ @root = File.dirname(where)
17
+ else
18
+ raise "#{self.class} must write to a file, so that we know where to store screenshots"
19
+ end
20
+ raise "Only one instance of #{self.class} is allowed" unless self.class.instance.nil?
21
+ ScreenshotFormatter.instance = self
22
+ end
23
+
24
+ # Takes screenshot and snapshot of the +browser+'s html.
25
+ # This method calls #screenshot! so that method should not be called
26
+ # when this method is used.
27
+ # This method *must* be called in an after(:each) block.
28
+ def take_screenshot_of(browser)
29
+ screenshot
30
+ save_html(browser)
31
+ end
32
+
33
+ # Takes a screenshot of the current window and saves it to disk.
34
+ # Use this method when you don't have a browser object.
35
+ def screenshot
36
+ png_path = File.join(@root, relative_png_path)
37
+ ensure_dir(png_path)
38
+ save_screenshot(png_path)
39
+ end
40
+
41
+ # Writes the HTML from +browser+ to disk
42
+ def save_html(browser)
43
+ ensure_dir(absolute_html_path)
44
+ File.open(absolute_html_path, "w") {|io| io.write(browser.html)}
45
+ end
46
+
47
+ def ensure_dir(file)
48
+ dir = File.dirname(file)
49
+ FileUtils.mkdir_p(dir) unless File.directory?(dir)
50
+ end
51
+
52
+ def absolute_png_path
53
+ File.join(@root, relative_png_path)
54
+ end
55
+
56
+ def relative_png_path
57
+ "images/#{current_example_number}.png"
58
+ end
59
+
60
+ def absolute_html_path
61
+ File.join(@root, relative_html_path)
62
+ end
63
+
64
+ def relative_html_path
65
+ "html/#{current_example_number}.html"
66
+ end
67
+
68
+ def global_scripts
69
+ super + <<-EOF
70
+ function showImage(e) {
71
+ w = window.open();
72
+ w.location = e.childNodes[0].src
73
+ }
74
+
75
+ // Lifted from Ruby RDoc
76
+ function toggleSource( id ) {
77
+ var elem
78
+ var link
79
+
80
+ if( document.getElementById )
81
+ {
82
+ elem = document.getElementById( id )
83
+ link = document.getElementById( "l_" + id )
84
+ }
85
+ else if ( document.all )
86
+ {
87
+ elem = eval( "document.all." + id )
88
+ link = eval( "document.all.l_" + id )
89
+ }
90
+ else
91
+ return false;
92
+
93
+ if( elem.style.display == "block" )
94
+ {
95
+ elem.style.display = "none"
96
+ link.innerHTML = "show snapshot"
97
+ }
98
+ else
99
+ {
100
+ elem.style.display = "block"
101
+ link.innerHTML = "hide snapshot"
102
+ }
103
+ }
104
+ EOF
105
+ end
106
+
107
+ def global_styles
108
+ super + <<-EOF
109
+ div.rspec-report textarea {
110
+ width: 100%;
111
+ }
112
+
113
+ div.rspec-report div.dyn-source {
114
+ background:#FFFFEE none repeat scroll 0%;
115
+ border:1px dotted black;
116
+ color:#000000;
117
+ display:none;
118
+ margin:0.5em 2em;
119
+ padding:0.5em;
120
+ }
121
+ EOF
122
+ end
123
+
124
+ def extra_failure_content(failure)
125
+ result = super(failure)
126
+ if File.exist?(absolute_png_path)
127
+ result += img_div
128
+ end
129
+ if File.exist?(absolute_html_path)
130
+ source_id = "#{current_example_number}_source"
131
+ result += " <div>[<a id=\"l_#{source_id}\" href=\"javascript:toggleSource('#{source_id}')\">show snapshot</a>]</div>\n"
132
+ result += " <div id=\"#{source_id}\" class=\"dyn-source\"><iframe src=\"#{relative_html_path}\" width=\"100%\" height=\"300px\"></iframe></div>\n"
133
+ end
134
+ result
135
+ end
136
+
137
+ def img_div
138
+ " <div><a href=\"#{relative_png_path}\"><img width=\"25%\" height=\"25%\" src=\"#{relative_png_path}\" /></a></div>\n"
139
+ end
140
+ end
141
+
142
+ # This formatter produces the same HTML as ScreenshotFormatter, except that
143
+ # it doesn't save screenshot PNGs and browser snapshot HTML source to disk.
144
+ # It is meant to be used from a Spec::Distributed master
145
+ class MasterScreenshotFormatter < ScreenshotFormatter
146
+ def screenshot
147
+ end
148
+
149
+ def save_html(browser)
150
+ end
151
+ end
152
+
153
+ # This formatter writes PNG and browser snapshot HTML to disk, just like its superclass,
154
+ # but it doesn't write the HTML report itself.
155
+ # It is meant to be used from Spec::Distributed slaves
156
+ class SlaveScreenshotFormatter < ScreenshotFormatter
157
+ def initialize(where)
158
+ super(where, StringIO.new)
159
+ end
160
+ end
161
+ end
162
+ end
@@ -23,8 +23,16 @@ module Spec
23
23
  nil
24
24
  rescue Magick::ImageMagickError => e
25
25
  if e.message =~ /Insufficient image data in file/
26
- e.message << "\nTry this:\n1) Open your app (e.g. Internet Explorer)\n2) Resize the app to be bigger (without maximizing).\n3) close it so Windows remembers its size.\n" +
27
- "This *may* make this error go away."
26
+ e.message << <<-EOM
27
+ This is a bug in win32screenshot - it fails to take screenshots of "small" windows. Try this workaround:
28
+
29
+ 1) Close all instances of the app you're trying to take a screenshot of (e.g. Internet Explorer)
30
+ 2) Open the app
31
+ 3) Resize the window so it occupies the entire screen (without maximizing it!)
32
+ 4) Exit the app. Windows will now remember its size the next time it starts.
33
+
34
+ This *may* make this error go away
35
+ EOM
28
36
  end
29
37
  raise e
30
38
  end
@@ -47,4 +55,4 @@ module Spec
47
55
  end
48
56
  end
49
57
  end
50
- end
58
+ end
@@ -1 +1 @@
1
- require 'spec/ui/selenium/driver_ext'
1
+ require 'spec/ui/selenium/driver_ext'
@@ -3,7 +3,7 @@ module Spec
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 0
5
5
  MINOR = 2
6
- TINY = 3
6
+ TINY = 4
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  end
@@ -34,4 +34,4 @@ class Watir::Browser
34
34
  raise e
35
35
  end
36
36
  end
37
- end
37
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec/ui/watir/matchers'
2
+
3
+ module Spec
4
+ module Ui
5
+ module Watir
6
+ class WatirBehaviour < Spec::DSL::Behaviour
7
+ def before_eval # :nodoc:
8
+ include Spec::Matchers::Watir
9
+ begin
10
+ # We'll try to hook up to the Rails stuff. This gives us access
11
+ # to transactional fixtures etc.
12
+ inherit Spec::Rails::DSL::EvalContext
13
+ prepend_before {setup}
14
+ append_after {teardown}
15
+ configure
16
+ rescue
17
+ end
18
+ end
19
+
20
+ Spec::DSL::BehaviourFactory.add_behaviour_class(:watir, self)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -37,4 +37,4 @@ describe "Browser" do
37
37
  end.should raise_error(Spec::Expectations::ExpectationNotMetError,
38
38
  'Expected BrowserStub to not have label(:foo, true), but it was found')
39
39
  end
40
- end
40
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: spec_ui
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.3
7
- date: 2007-05-24 00:00:00 +02:00
6
+ version: 0.2.4
7
+ date: 2007-08-12 00:00:00 -04:00
8
8
  summary: Run UI RSpec examples with screenshot reports
9
9
  require_paths:
10
10
  - lib
@@ -45,9 +45,10 @@ files:
45
45
  - lib/spec/ui/watir.rb
46
46
  - lib/spec/ui/watir/browser.rb
47
47
  - lib/spec/ui/watir/matchers.rb
48
+ - lib/spec/ui/watir/watir_behaviour.rb
48
49
  - examples/selenium/Rakefile
49
50
  - examples/selenium/README.txt
50
- - examples/selenium/spec/google/find_rspecs_homepage_spec.rb
51
+ - examples/selenium/spec/selenium/find_rspecs_homepage_spec.rb
51
52
  - examples/selenium/spec/spec_helper.rb
52
53
  - examples/watir/Rakefile
53
54
  - examples/watir/README.txt
@@ -57,10 +58,15 @@ files:
57
58
  - spec/spec/ui/watir/matchers_spec.rb
58
59
  test_files: []
59
60
 
60
- rdoc_options: []
61
-
62
- extra_rdoc_files: []
63
-
61
+ rdoc_options:
62
+ - --main
63
+ - README.txt
64
+ extra_rdoc_files:
65
+ - History.txt
66
+ - Manifest.txt
67
+ - README.txt
68
+ - examples/selenium/README.txt
69
+ - examples/watir/README.txt
64
70
  executables: []
65
71
 
66
72
  extensions: []
@@ -75,5 +81,5 @@ dependencies:
75
81
  requirements:
76
82
  - - ">="
77
83
  - !ruby/object:Gem::Version
78
- version: 1.2.0
84
+ version: 1.2.2
79
85
  version: