capybara-screenshot 0.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "capybara-screenshot"
16
16
 
17
- s.add_dependency 'capybara', '>= 1.0'
17
+ s.add_dependency 'capybara', ['>= 1.0', '< 3']
18
18
  s.add_development_dependency 'rspec', '~> 2.7'
19
19
  s.add_development_dependency 'timecop'
20
20
 
@@ -98,5 +98,9 @@ Capybara::Screenshot.class_eval do
98
98
  end
99
99
 
100
100
  require 'capybara/dsl'
101
+ require 'capybara/util/save_and_open_page' if Capybara::VERSION.match(/^\d+/)[0] == '1' # no longer needed in Capybara version 2
102
+
101
103
  require 'capybara-screenshot/saver'
102
- require 'capybara-screenshot/capybara'
104
+ require 'capybara-screenshot/capybara'
105
+
106
+
@@ -1,13 +1,15 @@
1
1
  RSpec.configure do |config|
2
2
  # use the before hook to add an after hook that runs last
3
- config.after(:type => :request) do
4
- if Capybara::Screenshot.autosave_on_failure && example.exception
5
- filename_prefix = Capybara::Screenshot.filename_prefix_for(:rspec, example)
3
+ config.after do
4
+ if Capybara.page.respond_to?(:save_page) # Capybara DSL method has been included for a feature we can snapshot
5
+ if Capybara::Screenshot.autosave_on_failure && example.exception
6
+ filename_prefix = Capybara::Screenshot.filename_prefix_for(:rspec, example)
6
7
 
7
- saver = Capybara::Screenshot::Saver.new(Capybara, Capybara.page, true, filename_prefix)
8
- saver.save
8
+ saver = Capybara::Screenshot::Saver.new(Capybara, Capybara.page, true, filename_prefix)
9
+ saver.save
9
10
 
10
- example.metadata[:full_description] += "\n Screenshot: #{saver.screenshot_path}"
11
+ example.metadata[:full_description] += "\n Screenshot: #{saver.screenshot_path}"
12
+ end
11
13
  end
12
14
  end
13
15
  end
@@ -5,7 +5,7 @@ module Capybara
5
5
 
6
6
  def initialize(capybara, page, html_save=true, filename_prefix='screenshot')
7
7
  @capybara, @page, @html_save = capybara, page, html_save
8
- @file_base_name = "#{filename_prefix}-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
8
+ @file_base_name = "#{filename_prefix}_#{Time.now.strftime('%Y-%m-%d-%H-%M-%S.%L')}"
9
9
  end
10
10
 
11
11
  def save
@@ -17,8 +17,12 @@ module Capybara
17
17
  end
18
18
 
19
19
  def save_html
20
- require 'capybara/util/save_and_open_page'
21
- capybara.save_page(page.body, "#{file_base_name}.html")
20
+ if Capybara::VERSION.match(/^\d+/)[0] == '1'
21
+ capybara.save_page(page.body, "#{file_base_name}.html")
22
+ else
23
+ capybara.save_page("#{file_base_name}.html")
24
+ end
25
+ warn "Saved file #{file_base_name}"
22
26
  end
23
27
 
24
28
  def save_screenshot
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Screenshot
3
- VERSION = "0.3"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
@@ -12,12 +12,12 @@ describe Capybara::Screenshot::Saver do
12
12
 
13
13
  before do
14
14
  Capybara::Screenshot.stub(:capybara_root).and_return(capybara_root)
15
- Timecop.freeze(Time.local(2012, 6, 7, 8, 9, 10))
15
+ Timecop.freeze(Time.local(2012, 6, 7, 8, 9, 10, 0))
16
16
  end
17
17
 
18
18
  let(:capybara_root) { '/tmp' }
19
- let(:timestamp) { '2012-06-07-08-09-10' }
20
- let(:file_basename) { "screenshot-#{timestamp}" }
19
+ let(:timestamp) { '2012-06-07-08-09-10.000' }
20
+ let(:file_basename) { "screenshot_#{timestamp}" }
21
21
  let(:screenshot_path) { "#{capybara_root}/#{file_basename}.png" }
22
22
 
23
23
  let(:driver_mock) { mock('Capybara driver').as_null_object }
@@ -31,8 +31,12 @@ describe Capybara::Screenshot::Saver do
31
31
 
32
32
  let(:saver) { Capybara::Screenshot::Saver.new(capybara_mock, page_mock) }
33
33
 
34
- context 'html filename' do
35
- it 'should have default format of "screenshot-Y-M-D-H-M-S.html"' do
34
+ context 'html filename with Capybara Version 1' do
35
+ before do
36
+ stub_const("Capybara::VERSION", '1')
37
+ end
38
+
39
+ it 'should have default format of "screenshot_Y-M-D-H-M-S.ms.html"' do
36
40
  capybara_mock.should_receive(:save_page).with('body', "#{file_basename}.html")
37
41
 
38
42
  saver.save
@@ -41,7 +45,27 @@ describe Capybara::Screenshot::Saver do
41
45
  it 'should use name argument as prefix' do
42
46
  saver = Capybara::Screenshot::Saver.new(capybara_mock, page_mock, true, 'custom-prefix')
43
47
 
44
- capybara_mock.should_receive(:save_page).with('body', "custom-prefix-#{timestamp}.html")
48
+ capybara_mock.should_receive(:save_page).with('body', "custom-prefix_#{timestamp}.html")
49
+
50
+ saver.save
51
+ end
52
+ end
53
+
54
+ context 'html filename with Capybara Version 2' do
55
+ before do
56
+ stub_const("Capybara::VERSION", '2')
57
+ end
58
+
59
+ it 'should have default format of "screenshot_Y-M-D-H-M-S.ms.html"' do
60
+ capybara_mock.should_receive(:save_page).with("#{file_basename}.html")
61
+
62
+ saver.save
63
+ end
64
+
65
+ it 'should use name argument as prefix' do
66
+ saver = Capybara::Screenshot::Saver.new(capybara_mock, page_mock, true, 'custom-prefix')
67
+
68
+ capybara_mock.should_receive(:save_page).with("custom-prefix_#{timestamp}.html")
45
69
 
46
70
  saver.save
47
71
  end
@@ -54,7 +78,7 @@ describe Capybara::Screenshot::Saver do
54
78
  saver.save
55
79
  end
56
80
 
57
- it 'should have default filename format of "screenshot-Y-M-D-H-M-S.png"' do
81
+ it 'should have default filename format of "screenshot_Y-M-D-H-M-S.ms.png"' do
58
82
  driver_mock.should_receive(:render).with(/#{file_basename}\.png$/)
59
83
 
60
84
  saver.save
@@ -62,7 +86,7 @@ describe Capybara::Screenshot::Saver do
62
86
 
63
87
  it 'should use filename prefix argument as basename prefix' do
64
88
  saver = Capybara::Screenshot::Saver.new(capybara_mock, page_mock, true, 'custom-prefix')
65
- driver_mock.should_receive(:render).with(/custom-prefix-#{timestamp}\.png$/)
89
+ driver_mock.should_receive(:render).with(/#{capybara_root}\/custom-prefix_#{timestamp}\.png$/)
66
90
 
67
91
  saver.save
68
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-screenshot
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-30 00:00:00.000000000 Z
12
+ date: 2012-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -19,6 +19,9 @@ dependencies:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '1.0'
22
+ - - <
23
+ - !ruby/object:Gem::Version
24
+ version: '3'
22
25
  type: :runtime
23
26
  prerelease: false
24
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,6 +30,9 @@ dependencies:
27
30
  - - ! '>='
28
31
  - !ruby/object:Gem::Version
29
32
  version: '1.0'
33
+ - - <
34
+ - !ruby/object:Gem::Version
35
+ version: '3'
30
36
  - !ruby/object:Gem::Dependency
31
37
  name: rspec
32
38
  requirement: !ruby/object:Gem::Requirement
@@ -100,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
106
  version: '0'
101
107
  segments:
102
108
  - 0
103
- hash: 1964539847270937869
109
+ hash: -502489258301273906
104
110
  required_rubygems_version: !ruby/object:Gem::Requirement
105
111
  none: false
106
112
  requirements:
@@ -109,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
115
  version: '0'
110
116
  segments:
111
117
  - 0
112
- hash: 1964539847270937869
118
+ hash: -502489258301273906
113
119
  requirements: []
114
120
  rubyforge_project: capybara-screenshot
115
121
  rubygems_version: 1.8.24