capybara-screenshot 0.1.1 → 0.1.2

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.
data/CHANGELOG.md CHANGED
@@ -0,0 +1,9 @@
1
+ 16 November 2011
2
+ ----------------
3
+
4
+ Added support for RSpec by adding a RSpec configuration after hook and checking if Capybara is being used.
5
+
6
+ 15 November 2011
7
+ ----------------
8
+
9
+ Ensured that tests run other than Cucumber won't fail. Prior to this Cucumber was required.
data/README.md CHANGED
@@ -18,6 +18,13 @@ or update your Gemfile to include:
18
18
 
19
19
  That's it!
20
20
 
21
+ Example application
22
+ -------------------
23
+
24
+ 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)
25
+ Git clone the app, and then run Cucumber `rake cucumber` or RSpec `rspec spec/**/*_spec.rb` and expect failures.
26
+ Then check the tmp/capybara folder for the automatic screen shots generated from failed tests.
27
+
21
28
  Repository
22
29
  ----------
23
30
 
@@ -13,4 +13,18 @@ if defined?(Cucumber::RbSupport::RbDsl)
13
13
  After do |scenario|
14
14
  screen_shot_and_save_page if scenario.failed?
15
15
  end
16
+ end
17
+
18
+ if defined?(RSpec)
19
+ # capybara rspec must be included first so that this config.after is added to
20
+ # RSpec hooks afterwards, and thus executed first
21
+ require 'capybara/rspec'
22
+ require 'capybara-screenshot/rspec'
23
+ RSpec.configure do |config|
24
+ config.after do
25
+ unless Capybara.current_path.blank?
26
+ Capybara::Screenshot::RSpec.screen_shot_and_save_page(Capybara.body)
27
+ end
28
+ end
29
+ end
16
30
  end
@@ -0,0 +1,11 @@
1
+ require 'capybara-screenshot/saver'
2
+
3
+ module Capybara
4
+ module Screenshot
5
+ class RSpec
6
+ def self.screen_shot_and_save_page(body)
7
+ Capybara::Screenshot::Saver.screen_shot_and_save_page Capybara, Capybara.body
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ module Capybara
2
+ module Screenshot
3
+ class Saver
4
+ def self.screen_shot_and_save_page(capybara, body)
5
+ require 'capybara/util/save_and_open_page'
6
+ path = "/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
7
+ capybara.save_page body, "#{path}.html"
8
+ if capybara.page.driver.respond_to?(:render)
9
+ path = if defined?(Rails)
10
+ Rails.root.join "#{capybara.save_and_open_page_path}#{path}.png"
11
+ else
12
+ # Sinatra support, untested
13
+ File.join settings.root "#{capybara.save_and_open_page_path}#{path}.png"
14
+ end
15
+ capybara.page.driver.render path
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Screenshot
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -1,13 +1,10 @@
1
+ require 'capybara-screenshot/saver'
2
+
1
3
  module Capybara
2
4
  module Screenshot
3
5
  module World
4
6
  def screen_shot_and_save_page
5
- require 'capybara/util/save_and_open_page'
6
- path = "/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
7
- Capybara.save_page body, "#{path}.html"
8
- if page.driver.respond_to?(:render)
9
- page.driver.render Rails.root.join "#{Capybara.save_and_open_page_path}" "#{path}.png"
10
- end
7
+ Capybara::Screenshot::Saver.screen_shot_and_save_page Capybara, body
11
8
  end
12
9
  end
13
10
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-screenshot
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew O'Riordan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-15 00:00:00 +00:00
18
+ date: 2011-11-16 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -81,6 +81,8 @@ files:
81
81
  - Rakefile
82
82
  - capybara-screenshot.gemspec
83
83
  - lib/capybara-screenshot.rb
84
+ - lib/capybara-screenshot/rspec.rb
85
+ - lib/capybara-screenshot/saver.rb
84
86
  - lib/capybara-screenshot/version.rb
85
87
  - lib/capybara-screenshot/world.rb
86
88
  has_rdoc: true