cucumber-screenshot 0.1.0-universal-darwin

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ *.gemspec
2
+ pkg/*
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009 Joel Chippindale
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ = Cucumber Screenshot
2
+
3
+ Cucumber Screenshot adds a new output format to Cucumber that captures
4
+ screenshots of the pages generated by your Rails application as it runs your
5
+ Cucumber/Webrat features.
6
+
7
+ It uses WebKit to generate the screenshots and so is only available for OS X.
8
+
9
+ == Requirements
10
+
11
+ A Rails application with some features written in Cucumber/Webrat.
12
+
13
+ == Install
14
+
15
+ To install the latest release as a gem
16
+
17
+ sudo gem install cucumber-screenshot
18
+
19
+ == Use
20
+
21
+ Add the following line to your ./features/support/env.rb file
22
+
23
+ require 'cucumber_screenshot'
24
+
25
+ and then run
26
+
27
+ cucumber features --format screenshot
28
+
29
+ from your Rails application's directory.
30
+
31
+ This will create a ./features/screenshots directory in your Rails application
32
+ with subfolders for each scenario. Each subfolder will contain a screenshot of
33
+ each page generated and the html source of each of those pages.
34
+
35
+ == Capturing a single screenshot
36
+
37
+ If you want to capture a single screenshot rather than every page then add the
38
+ following step to one of your Rails application's step files
39
+
40
+ sudo gem install webratThen "screenshot" do
41
+ screenshot.should be_true
42
+ end
43
+
44
+ and then add
45
+
46
+ Then screenshot
47
+
48
+ to your feature file in the place where you want to capture a screenshot of the
49
+ page that your application geneerated.
50
+
51
+ == TODO
52
+
53
+ - Clean out existing snapshots before each run
54
+ - Add support for tables
55
+
56
+ == License
57
+
58
+ Copyright (c) 2009 Joel Chippindale.
59
+ See MIT-LICENSE.txt in this directory.
@@ -0,0 +1,30 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "cucumber-screenshot"
5
+ gemspec.summary = "Cucumber formatter that outputs PNG screenshots of your app"
6
+ gemspec.description = "Cucumber (http://cukes.info/) formatter that uses Webkit to capture PNG screenshots of your web application during tests"
7
+ gemspec.platform = "universal-darwin"
8
+ gemspec.requirements << "Mac OS X 10.5 or later"
9
+ gemspec.requirements << "RubyCocoa"
10
+ gemspec.add_dependency('cucumber', '>= 0.3.9')
11
+ gemspec.add_dependency('webrat', '>= 0.5.3')
12
+ gemspec.add_dependency('mocoso-snapurl', '>= 0.0.3')
13
+ gemspec.email = 'joel.chippindale@gmail.com'
14
+ gemspec.authors = ['Joel Chippindale']
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ begin
22
+ require 'spec/rake/spectask'
23
+ desc "Run the cucumber-screenshot specs"
24
+ Spec::Rake::SpecTask.new('spec') do |t|
25
+ t.spec_files = FileList['spec/**/*_spec.rb']
26
+ t.spec_opts = ['--options', 'spec/spec.opts']
27
+ end
28
+ rescue LoadError
29
+ puts 'Rspec not available, install it with: sudo gem install rspec'
30
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 0
3
+ :major: 0
4
+ :minor: 1
@@ -0,0 +1,17 @@
1
+ require 'cucumber'
2
+ require 'webrat'
3
+
4
+ require 'cucumber_screenshot/formatter'
5
+ require 'cucumber_screenshot/webrat/session'
6
+
7
+ # Add formatter to Cucumber's built in list so you can use
8
+ #
9
+ # --format screenshot
10
+ #
11
+ # as well as
12
+ #
13
+ # --format Cucumber::Format::Screenshot
14
+ Cucumber::Cli::Configuration::BUILTIN_FORMATS['screenshot'] = 'CucumberScreenshot::Formatter'
15
+
16
+ # Make screenshot method available to steps
17
+ Webrat::Methods.delegate_to_session :screenshot
@@ -0,0 +1,63 @@
1
+ module CucumberScreenshot
2
+ class Formatter < Cucumber::Ast::Visitor
3
+
4
+ attr_accessor :response_body_for_last_screenshot, :screenshot_index, :screenshot_directory, :current_feature_segment, :current_scenario_segment
5
+
6
+ # Currently ignores io and options arguments
7
+ def initialize(step_mother, io, options)
8
+ super(step_mother)
9
+ @io = io
10
+ @options = options
11
+ end
12
+
13
+ def visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
14
+ if screenshot_due?
15
+ self.screenshot_index = screenshot_index.next
16
+ exit unless session.screenshot(screenshot_directory_name, "screenshot-#{format('%03d', screenshot_index)}")
17
+ self.response_body_for_last_screenshot = current_response_body
18
+ end
19
+ super
20
+ end
21
+
22
+ def visit_scenario_name(keyword, name, file_colon_line, source_indent)
23
+ puts "Scenario #{name}"
24
+ self.response_body_for_last_screenshot = nil
25
+ self.screenshot_index = 0
26
+ self.current_scenario_segment = segment_for_scenario_named(name)
27
+ end
28
+
29
+ def visit_feature(feature)
30
+ self.current_feature_segment = segment_for_feature(feature)
31
+ super
32
+ end
33
+
34
+ def visit_feature_name(name)
35
+ puts(name)
36
+ end
37
+
38
+ protected
39
+ def screenshot_directory_name
40
+ File.join(session.base_screenshot_directory_name, current_feature_segment, current_scenario_segment)
41
+ end
42
+
43
+ def segment_for_feature(feature)
44
+ feature.file.gsub(/^features\//, '').gsub(/\.feature$/, '')
45
+ end
46
+
47
+ def segment_for_scenario_named(name)
48
+ name.downcase.gsub(' ', '_').gsub(/(\(|\))/, '')
49
+ end
50
+
51
+ def session
52
+ step_mother.current_world.webrat_session
53
+ end
54
+
55
+ def current_response_body
56
+ session.send(:response) && session.response_body
57
+ end
58
+
59
+ def screenshot_due?
60
+ current_response_body && current_response_body != response_body_for_last_screenshot && !session.redirect?
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,53 @@
1
+ module CucumberScreenshot
2
+ module Webrat
3
+ module Session #:nodoc:
4
+
5
+ def base_screenshot_directory_name
6
+ # TODO: Make this configurable
7
+ # TODO: Make this work for other frameworks e.g. sinatra
8
+ "#{RAILS_ROOT}/features/screenshots"
9
+ end
10
+
11
+ def screenshot(directory_name = base_screenshot_directory_name, file_name = "screenshot-#{Time.now.to_i}")
12
+ File.makedirs("#{directory_name}/html")
13
+
14
+ html_file_name = "#{directory_name}/html/#{file_name}.html"
15
+ File.open(html_file_name, "w") do |f|
16
+ f.write rewrite_javascript_and_css_and_image_references(response_body)
17
+ end
18
+
19
+ command = "snapurl file://#{html_file_name} --no-thumbnail --no-clip --filename #{file_name} --output-dir #{directory_name}"
20
+ `#{command}`
21
+ if $? == 0
22
+ puts "- Screenshot saved to #{directory_name}/#{file_name}.png\n"
23
+ true
24
+ else
25
+ report_error_running_screenshot_command(command)
26
+ false
27
+ end
28
+ end
29
+
30
+ protected
31
+ def rewrite_javascript_and_css_and_image_references(response_html) # :nodoc:
32
+ return response_html unless doc_root
33
+ rewrite_css_and_image_references(response_html).gsub(/"\/(javascript)/, doc_root + '/\1')
34
+ end
35
+
36
+ def report_error_running_screenshot_command(command)
37
+ STDERR.puts "
38
+ Unable to make screenshot, to find out what went wrong try the following from the command line
39
+
40
+ #{command}
41
+
42
+ Please remember need to have installed the gem mocoso-snapshoturl to take screenshots
43
+
44
+ gem install mocoso-snapshoturl
45
+
46
+ "
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ Webrat::Session.send(:include, CucumberScreenshot::Webrat::Session)
53
+
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module CucumberScreenshot
4
+ describe Formatter do
5
+ describe '#visit_scenario_named' do
6
+ before(:each) do
7
+ @formatter = Formatter.new(stub('step_mother'), nil, {})
8
+ end
9
+ it "set current_scenario_segment from scenario name" do
10
+ lambda { @formatter.visit_scenario_name(nil, 'Login (when already has an account)', 1, 2) }.should change(@formatter, :current_scenario_segment).to('login_when_already_has_an_account')
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module CucumberScreenshot
4
+ module Webrat
5
+ describe Session do
6
+ describe '#base_screenshot_directory_name' do
7
+ it "add features/screenshots to rails root" do
8
+ ::RAILS_ROOT = 'tmp'
9
+ ::Webrat::Session.new.base_screenshot_directory_name.should == 'tmp/features/screenshots'
10
+ end
11
+ end
12
+
13
+ describe '#screenshot' do
14
+ before(:each) do
15
+ @html_file = stub('html_file', :write => true)
16
+ File.stub!(:makedirs => true, :open => @html_file)
17
+ @session = ::Webrat::Session.new
18
+ @session.stub!(:base_screenshot_directory_name => 'tmp/features/screenshots', :response_body => 'foo')
19
+ @session.stub!(:` => 'foo')
20
+ @session.stub!(:report_error_running_screenshot_command => true) # While $? is not being set by the backtick stub
21
+ end
22
+
23
+ it 'should call File.makedirs' do
24
+ File.should_receive(:makedirs).with('1/2/html').and_return(true)
25
+ @session.screenshot('1/2', 'snapshot-001')
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
@@ -0,0 +1,4 @@
1
+ SPEC_DIR = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'cucumber_screenshot'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-screenshot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: universal-darwin
6
+ authors:
7
+ - Joel Chippindale
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-19 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: cucumber
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: webrat
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.3
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: mocoso-snapurl
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.0.3
44
+ version:
45
+ description: Cucumber (http://cukes.info/) formatter that uses Webkit to capture PNG screenshots of your web application during tests
46
+ email: joel.chippindale@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README.rdoc
53
+ files:
54
+ - .gitignore
55
+ - MIT-LICENSE
56
+ - README.rdoc
57
+ - Rakefile
58
+ - VERSION.yml
59
+ - lib/cucumber_screenshot.rb
60
+ - lib/cucumber_screenshot/formatter.rb
61
+ - lib/cucumber_screenshot/webrat/session.rb
62
+ - spec/cucumber_screenshot/formatter_spec.rb
63
+ - spec/cucumber_screenshot/webrat/session_spec.rb
64
+ - spec/spec.opts
65
+ - spec/spec_helper.rb
66
+ has_rdoc: true
67
+ homepage:
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --charset=UTF-8
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ requirements:
88
+ - Mac OS X 10.5 or later
89
+ - RubyCocoa
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.5
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Cucumber formatter that outputs PNG screenshots of your app
95
+ test_files:
96
+ - spec/cucumber_screenshot/formatter_spec.rb
97
+ - spec/cucumber_screenshot/webrat/session_spec.rb
98
+ - spec/spec_helper.rb