capybara-screenshot 0.2.4 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ 30 Oct 2012 - Significant version bump 0.3
2
+ -----------
3
+
4
+ After some consideration, and continued problems with load order of capybara-screenshot in relation to other required gems, the commits from @adzap in the pull request https://github.com/mattheworiordan/capybara-screenshot/pull/29 have been incorporated. Moving forwards, for every testing framework you use, you will be required to add an explicit require.
5
+
6
+
1
7
  15 Feb 2012
2
8
  -----------
3
9
 
data/README.md CHANGED
@@ -5,34 +5,55 @@ Using this gem, whenever a [Capybara](https://github.com/jnicklas/capybara) test
5
5
 
6
6
  This is a huge help when trying to diagnose a problem in your failing steps as you can view the source code and potentially how the page looked at the time of the failure.
7
7
 
8
- Usage
8
+ Installation
9
9
  -----
10
10
 
11
- gem install capybara-screenshot
11
+ ### Step 1
12
12
 
13
- or update your Gemfile to include `capybara-screenshot` at the bottom (order respected as of Bundler 0.10):
13
+ Using Bundler, add the following to your Gemfile
14
14
 
15
15
  gem 'capybara-screenshot', :group => :test
16
16
 
17
+ or install manually using Ruby Gems:
18
+
19
+ gem install capybara-screenshot
20
+
21
+ ### Step 2
22
+
23
+ For **Cucumber**, in env.rb or a support file, please add:
24
+
25
+ require 'capybara-screenshot/cucumber'
26
+
27
+ For **RSpec**, in spec_helper.rb or a support file, after the require for 'capybara/rspec', please add:
28
+
29
+ # you should require 'capybara/rspec' first
30
+ require 'capybara-screenshot/rspec'
31
+
32
+ For **Minitest**, typically in 'test/test_helper.rb', please add:
33
+
34
+ require 'capybara-screenshot/minitest'
35
+
36
+ Manual screenshots
37
+ ----
38
+
17
39
  If you require more control, you can generate the screenshot on demand rather than on failure. This is useful
18
40
  if the failure occurs at a point where the screen shot is not as useful for debugging a rendering problem. This
19
41
  can be more useful if you disable the auto-generate on failure feature with the following config
20
42
 
21
43
  Capybara::Screenshot.autosave_on_failure = false
22
44
 
23
- Anywhere the Capybara DSL methods (visit, click etc.) are available so too will are the screenshot methods.
45
+ Anywhere the Capybara DSL methods (visit, click etc.) are available so too are the screenshot methods.
24
46
 
25
- screen_shot_and_save_page
47
+ screenshot_and_save_page
26
48
 
27
49
  Or for screenshot only, which will automatically open the image.
28
50
 
29
- screen_shot_and_open_image
51
+ screenshot_and_open_image
30
52
 
31
53
  These are just calls on the main library methods.
32
54
 
33
- Capybara::Screenshot.screen_shot_and_save_page
34
-
35
- Capybara::Screenshot.screen_shot_and_open_image
55
+ Capybara::Screenshot.screenshot_and_save_page
56
+ Capybara::Screenshot.screenshot_and_open_image
36
57
 
37
58
 
38
59
  Driver configuration
@@ -70,17 +91,14 @@ Example application
70
91
  -------------------
71
92
 
72
93
  A simple Rails 3.1 example application has been set up at [https://github.com/mattheworiordan/capybara-screenshot-test-rails-3.1](https://github.com/mattheworiordan/capybara-screenshot-test-rails-3.1)
73
- Git clone the app, and then run Cucumber `rake cucumber`, RSpec `rspec spec/**/*_spec.rb` and Minitest `rake test` and expect intentional failures.
94
+ Git clone the app, and then run Cucumber `rake cucumber`, RSpec `rake spec` and Minitest `rake test` and expect intentional failures.
74
95
  Now check the $APPLICATION_ROOT/tmp/capybara folder for the automatic screen shots generated from failed tests.
75
96
 
97
+
76
98
  Common problems
77
99
  ---------------
78
100
 
79
- If you find that screen shots are not automatically being generated, then it's possible the `capybara-screenshot` gem is loading before your testing framework is loading, and thus unable to determine which framework to hook into. Make sure you include `capybara-screenshot` gem last in your Gemfile (order is respected by Bundler as of 0.10). Alternatively, manually require `capybara-screenshot` using one of the following based on your framework:
80
-
81
- require 'capybara-screenshot/cucumber' # For Cucumber support
82
- require 'capybara-screenshot/rspec' # For RSpec support
83
- require 'capybara-screenshot/minitest' # For MiniSpec support
101
+ If you have recently upgraded from v0.2, or you find that screen shots are not automatically being generated, then it's most likely you have not included the necessary `require` statement for your testing framework described above. As of version 0.3, without the explicit require, Capybara-Screenshot will not automatically take screen shots. Please re-read the installation instructions above.
84
102
 
85
103
  [Raise an issue on the Capybara-Screenshot issue tracker](https://github.com/mattheworiordan/capybara-screenshot/issues) if you are still having problems.
86
104
 
@@ -103,4 +121,4 @@ This gem was written by **Matthew O'Riordan**
103
121
  License
104
122
  -------
105
123
 
106
- Copyright © 2012 Matthew O'Riordan, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.
124
+ Copyright © 2012 Matthew O'Riordan, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.
@@ -10,19 +10,24 @@ module Capybara
10
10
  self.registered_drivers = {}
11
11
  self.filename_prefix_formatters = {}
12
12
 
13
- def self.screen_shot_and_save_page
13
+ def self.screenshot_and_save_page
14
14
  saver = Saver.new(Capybara, Capybara.page)
15
15
  saver.save
16
16
  {:html => saver.html_path, :image => saver.screenshot_path}
17
17
  end
18
18
 
19
- def self.screen_shot_and_open_image
19
+ def self.screenshot_and_open_image
20
20
  require "launchy"
21
21
 
22
22
  saver = Saver.new(Capybara, Capybara.page, false)
23
23
  saver.save
24
24
  Launchy.open saver.screenshot_path
25
- {:html => saver.html_path, :image => saver.screenshot_path}
25
+ {:html => nil, :image => saver.screenshot_path}
26
+ end
27
+
28
+ class << self
29
+ alias screen_shot_and_save_page screenshot_and_save_page
30
+ alias screen_shot_and_open_image screenshot_and_open_image
26
31
  end
27
32
 
28
33
  def self.filename_prefix_for(test_type, test)
@@ -92,14 +97,6 @@ Capybara::Screenshot.class_eval do
92
97
  end
93
98
  end
94
99
 
100
+ require 'capybara/dsl'
95
101
  require 'capybara-screenshot/saver'
96
- require 'capybara-screenshot/capybara'
97
-
98
- # do nothing if Cucumber is not being used
99
- if defined?(Cucumber::RbSupport::RbDsl)
100
- require 'capybara/cucumber'
101
- require 'capybara-screenshot/cucumber'
102
- end
103
-
104
- require 'capybara-screenshot/rspec' if defined?(RSpec)
105
- require 'capybara-screenshot/minitest' if defined?(MiniTest)
102
+ require 'capybara-screenshot/capybara'
@@ -3,12 +3,12 @@ module Capybara
3
3
  # Adds class methods to Capybara module and gets mixed into
4
4
  # the current scope during Cucumber and RSpec tests
5
5
 
6
- def screen_shot_and_save_page
7
- Capybara::Screenshot.screen_shot_and_save_page
6
+ def screenshot_and_save_page
7
+ Capybara::Screenshot.screenshot_and_save_page
8
8
  end
9
9
 
10
- def screen_shot_and_open_image
11
- Capybara::Screenshot.screen_shot_and_open_image
10
+ def screenshot_and_open_image
11
+ Capybara::Screenshot.screenshot_and_open_image
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -1,26 +1,24 @@
1
- if defined?(ActionDispatch::IntegrationTest)
2
- method = if ActionDispatch::IntegrationTest.respond_to? :teardown
3
- :teardown
4
- elsif ActionDispatch::IntegrationTest.respond_to? :add_tear_down_hook
5
- :add_tear_down_hook
6
- end
1
+ method = if ActionDispatch::IntegrationTest.respond_to? :teardown
2
+ :teardown
3
+ elsif ActionDispatch::IntegrationTest.respond_to? :add_tear_down_hook
4
+ :add_tear_down_hook
5
+ end
7
6
 
8
- unless method.nil?
9
- begin
10
- ActionDispatch::IntegrationTest.send method do |context|
11
- # by adding the argument context, MiniTest passes the context of the test
12
- # which has an instance variable @passed indicating success / failure
13
- failed = context.instance_variable_get(:@passed).blank?
7
+ unless method.nil?
8
+ begin
9
+ ActionDispatch::IntegrationTest.send method do |context|
10
+ # by adding the argument context, MiniTest passes the context of the test
11
+ # which has an instance variable @passed indicating success / failure
12
+ failed = context.instance_variable_get(:@passed).blank?
14
13
 
15
- if Capybara::Screenshot.autosave_on_failure && failed
16
- filename_prefix = Capybara::Screenshot.filename_prefix_for(:minitest, context)
14
+ if Capybara::Screenshot.autosave_on_failure && failed
15
+ filename_prefix = Capybara::Screenshot.filename_prefix_for(:minitest, context)
17
16
 
18
- saver = Capybara::Screenshot::Saver.new(Capybara, Capybara.page, true, filename_prefix)
19
- saver.save
20
- end
17
+ saver = Capybara::Screenshot::Saver.new(Capybara, Capybara.page, true, filename_prefix)
18
+ saver.save
21
19
  end
22
- rescue NoMethodError
23
- # do nothing, teardown for minitest not available
24
20
  end
21
+ rescue NoMethodError
22
+ # do nothing, teardown for minitest not available
25
23
  end
26
24
  end
@@ -1,43 +1,13 @@
1
1
  RSpec.configure do |config|
2
2
  # use the before hook to add an after hook that runs last
3
- config.before(:type => :request) do
4
- Capybara::Screenshot::RSpec.add_after(example.example_group) do
5
- if Capybara::Screenshot.autosave_on_failure && example.exception
6
- filename_prefix = Capybara::Screenshot.filename_prefix_for(:rspec, example)
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)
7
6
 
8
- saver = Capybara::Screenshot::Saver.new(Capybara, Capybara.page, true, filename_prefix)
9
- saver.save
7
+ saver = Capybara::Screenshot::Saver.new(Capybara, Capybara.page, true, filename_prefix)
8
+ saver.save
10
9
 
11
- example.metadata[:full_description] += "\n Screenshot: #{saver.screenshot_path}"
12
- end
10
+ example.metadata[:full_description] += "\n Screenshot: #{saver.screenshot_path}"
13
11
  end
14
12
  end
15
- end
16
-
17
- # keep a record of which example groups we've added an after hook to and add if one does not exist
18
- module Capybara
19
- module Screenshot
20
- class RSpec
21
- @@example_groups = []
22
- def self.add_after(example_group, &block)
23
- unless (@@example_groups & self_and_parents(example_group)).count > 0
24
- example_group.after :each, &block
25
- @@example_groups << example_group
26
- end
27
- end
28
-
29
- private
30
- # Return an array of current ExampleGroup and all parent ExampleGroups other than Core which has no metadata
31
- def self.self_and_parents(example_group, children = [])
32
- parent_is_core = example_group.superclass.metadata.nil? rescue true # don't ever raise an error if RSpec API changes in the future, lets rather do multiple screen shots as a side effect
33
- if parent_is_core
34
- children << example_group
35
- children
36
- else
37
- children << example_group
38
- self_and_parents(example_group.superclass, children)
39
- end
40
- end
41
- end
42
- end
43
- end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Screenshot
3
- VERSION = "0.2.4"
3
+ VERSION = "0.3"
4
4
  end
5
5
  end
@@ -4,14 +4,14 @@ module Capybara::Screenshot
4
4
  describe Capybara do
5
5
 
6
6
  it 'should add screen shot methods to the Capybara module' do
7
- ::Capybara.should respond_to(:screen_shot_and_save_page)
8
- ::Capybara.should respond_to(:screen_shot_and_open_image)
7
+ ::Capybara.should respond_to(:screenshot_and_save_page)
8
+ ::Capybara.should respond_to(:screenshot_and_open_image)
9
9
  end
10
10
 
11
11
  context 'request type example', :type => :request do
12
12
  it 'should have access to screen shot instance methods' do
13
- self.should respond_to(:screen_shot_and_save_page)
14
- self.should respond_to(:screen_shot_and_open_image)
13
+ self.should respond_to(:screenshot_and_save_page)
14
+ self.should respond_to(:screenshot_and_open_image)
15
15
  end
16
16
  end
17
17
  end
@@ -7,6 +7,7 @@
7
7
 
8
8
  $: << '../lib'
9
9
  require 'capybara-screenshot'
10
+ require 'capybara-screenshot/rspec'
10
11
  require 'timecop'
11
12
 
12
13
  RSpec.configure do |config|
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.2.4
4
+ version: '0.3'
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-17 00:00:00.000000000 Z
12
+ date: 2012-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara
@@ -100,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  segments:
102
102
  - 0
103
- hash: -2394325955606346377
103
+ hash: 1964539847270937869
104
104
  required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  segments:
111
111
  - 0
112
- hash: -2394325955606346377
112
+ hash: 1964539847270937869
113
113
  requirements: []
114
114
  rubyforge_project: capybara-screenshot
115
115
  rubygems_version: 1.8.24