cucumber-screenshot 0.2.0-universal-darwin → 0.2.1-universal-darwin
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +28 -19
- data/Rakefile +5 -4
- data/VERSION.yml +1 -1
- data/lib/cucumber_screenshot/world.rb +18 -20
- data/lib/cucumber_screenshot.rb +1 -2
- data/spec/cucumber_screenshot/world_spec.rb +59 -9
- metadata +8 -11
- data/lib/cucumber_screenshot/extensions.rb +0 -54
- data/spec/cucumber_screenshot/extensions_spec.rb +0 -30
data/README.rdoc
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
= Cucumber Screenshot
|
2
2
|
|
3
|
-
Cucumber Screenshot
|
4
|
-
|
5
|
-
Cucumber/Webrat features.
|
3
|
+
Cucumber Screenshot makes it easy to capture screenshots of the pages generated
|
4
|
+
by your Rails application as it runs your Cucumber/Webrat features.
|
6
5
|
|
7
6
|
It uses WebKit to generate the screenshots and so is only available for OS X.
|
8
7
|
|
8
|
+
If you want to take screenshots on any other platform then take a look at
|
9
|
+
[this example]http://github.com/aslakhellesoy/cucumber/blob/master/examples/watir/features/support/screenshots.rb
|
10
|
+
from Cucumber.
|
11
|
+
|
9
12
|
== Requirements
|
10
13
|
|
11
14
|
A Rails application with some features written in Cucumber/Webrat.
|
@@ -18,29 +21,34 @@ To install the latest release as a gem
|
|
18
21
|
|
19
22
|
== Use
|
20
23
|
|
21
|
-
|
22
|
-
project.
|
24
|
+
Create a cucumber_screenshot_env.rb file in the ./features/support/ directory
|
25
|
+
in your Rails project and put the following in it.
|
23
26
|
|
24
|
-
|
25
|
-
|
27
|
+
begin
|
28
|
+
require 'cucumber_screenshot'
|
29
|
+
World(CucumberScreenshot::World)
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
After do |scenario|
|
32
|
+
if scenario.failed?
|
33
|
+
screenshot
|
34
|
+
end
|
31
35
|
end
|
32
|
-
end
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
AfterStep('@screenshot') do |scenario|
|
38
|
+
if screenshot_due?
|
39
|
+
screenshot
|
40
|
+
end
|
38
41
|
end
|
42
|
+
rescue Exception => e
|
43
|
+
puts "Snapshots not available for this environment. Try installing
|
44
|
+
cucumber-screenshot with\n\n gem install cucumber-screenshot\n"
|
39
45
|
end
|
40
46
|
|
41
|
-
Then use the 'rake cucumber' and 'rake cucumber:wip' tasks as per usual
|
47
|
+
Then use the 'rake cucumber' and 'rake cucumber:wip' tasks as per usual.
|
42
48
|
|
43
|
-
Screenshots will be
|
49
|
+
Screenshots will be captured for every step failure and for every step in
|
50
|
+
scenarios tagged @screenshot. The screenshots will be saved to a
|
51
|
+
./features/screenshots/ directory in your project.
|
44
52
|
|
45
53
|
=== Capturing a single screenshot
|
46
54
|
|
@@ -50,7 +58,7 @@ following step to one of your Rails application's step files
|
|
50
58
|
Then "screenshot" do
|
51
59
|
screenshot
|
52
60
|
end
|
53
|
-
|
61
|
+
|
54
62
|
and then add
|
55
63
|
|
56
64
|
Then screenshot
|
@@ -62,6 +70,7 @@ page that your application generated.
|
|
62
70
|
|
63
71
|
- Clean out existing snapshots before each run
|
64
72
|
- Add support for tables
|
73
|
+
- Add a Rails generator to add the env and step code to a project
|
65
74
|
|
66
75
|
== License
|
67
76
|
|
data/Rakefile
CHANGED
@@ -2,16 +2,17 @@ begin
|
|
2
2
|
require 'jeweler'
|
3
3
|
Jeweler::Tasks.new do |gemspec|
|
4
4
|
gemspec.name = "cucumber-screenshot"
|
5
|
-
gemspec.summary = "Cucumber
|
6
|
-
gemspec.description = "Cucumber (http://cukes.info/)
|
5
|
+
gemspec.summary = "Extension for Cucumber to capture PNG screenshots of your app"
|
6
|
+
gemspec.description = "Extension for Cucumber (http://cukes.info/) that makes it easy to use Webkit to capture PNG screenshots of your web application during tests"
|
7
7
|
gemspec.platform = "universal-darwin"
|
8
8
|
gemspec.requirements << "Mac OS X 10.5 or later"
|
9
9
|
gemspec.requirements << "RubyCocoa"
|
10
|
-
gemspec.add_dependency('cucumber', '
|
11
|
-
gemspec.add_dependency('webrat', '
|
10
|
+
gemspec.add_dependency('cucumber', '>= 0.4.3')
|
11
|
+
gemspec.add_dependency('webrat', '>= 0.5.3')
|
12
12
|
gemspec.add_dependency('snapurl', '>= 0.0.3')
|
13
13
|
gemspec.email = 'joel.chippindale@gmail.com'
|
14
14
|
gemspec.authors = ['Joel Chippindale']
|
15
|
+
gemspec.homepage = 'http://github.com/mocoso/cucumber-screenshot'
|
15
16
|
end
|
16
17
|
Jeweler::GemcutterTasks.new
|
17
18
|
rescue LoadError
|
data/VERSION.yml
CHANGED
@@ -10,22 +10,24 @@ module CucumberScreenshot
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def screenshot(directory_name = base_screenshot_directory_name, file_name = "screenshot-#{(Time.now.to_f * 100).to_i}")
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
13
|
+
if current_response_body
|
14
|
+
FileUtils.mkdir_p("#{directory_name}/html")
|
15
|
+
|
16
|
+
html_file_name = "#{directory_name}/html/#{file_name}.html"
|
17
|
+
File.open(html_file_name, "w") do |f|
|
18
|
+
f.write rewrite_javascript_and_css_and_image_references(current_response_body)
|
19
|
+
end
|
20
|
+
|
21
|
+
command = "snapurl file://#{html_file_name} --no-thumbnail --no-clip --filename #{file_name} --output-dir #{directory_name}"
|
22
|
+
`#{command}`
|
23
|
+
if $? == 0
|
24
|
+
embed "#{directory_name}/#{file_name}.png", 'image/png'
|
25
|
+
self.response_body_for_last_screenshot = current_response_body
|
26
|
+
true
|
27
|
+
else
|
28
|
+
report_error_running_screenshot_command(command)
|
29
|
+
false
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
@@ -33,10 +35,6 @@ module CucumberScreenshot
|
|
33
35
|
current_response_body && current_response_body != response_body_for_last_screenshot && !webrat_session.redirect?
|
34
36
|
end
|
35
37
|
|
36
|
-
def embed_image(image_path)
|
37
|
-
@__cucumber_step_mother.embed_image(image_path)
|
38
|
-
end
|
39
|
-
|
40
38
|
protected
|
41
39
|
def current_response_body
|
42
40
|
webrat_session.send(:response) && webrat_session.response_body
|
data/lib/cucumber_screenshot.rb
CHANGED
@@ -18,22 +18,72 @@ describe CucumberScreenshot::World do
|
|
18
18
|
|
19
19
|
describe '#screenshot' do
|
20
20
|
before(:each) do
|
21
|
+
@session.stub!(
|
22
|
+
:webrat_session => stub('webrat_session', :send => true, :response_body => 'response html'),
|
23
|
+
:rewrite_javascript_and_css_and_image_references => 'rewritten response html',
|
24
|
+
:embed => true
|
25
|
+
)
|
26
|
+
|
27
|
+
# Stub with a command line call, required because don't know of other way to set $? to 0
|
28
|
+
# TODO: Replace with mechanism that doesn't require this call
|
29
|
+
@session.stub!(:'`').and_return { |args| `ruby -e 'true'` }
|
30
|
+
|
21
31
|
FileUtils.stub!(:mkdir_p => true)
|
22
|
-
|
23
|
-
|
24
|
-
@session.stub!(:'`' => 'foo')
|
25
|
-
# While $? is not being set by the backtick stub
|
26
|
-
@session.stub!(:report_error_running_screenshot_command => true)
|
32
|
+
@file = stub('file', :write => true)
|
33
|
+
File.stub!(:open).and_yield(@file)
|
27
34
|
end
|
28
35
|
|
29
36
|
it 'should call File.makedirs' do
|
30
|
-
FileUtils.should_receive(:mkdir_p).with('1/2/html').and_return(true)
|
31
|
-
@session.screenshot('1/2', 'snapshot-001')
|
37
|
+
FileUtils.should_receive(:mkdir_p).with('/1/2/html').and_return(true)
|
38
|
+
@session.screenshot('/1/2', 'snapshot-001')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should open a file ' do
|
42
|
+
File.should_receive(:open).with('/1/2/html/snapshot-001.html', 'w').and_yield(@file)
|
43
|
+
@session.screenshot('/1/2', 'snapshot-001')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should write to file' do
|
47
|
+
@file.should_receive(:write).with('rewritten response html')
|
48
|
+
@session.screenshot('/1/2', 'snapshot-001')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should call snapurl' do
|
52
|
+
@session.should_receive(:'`') do |args|
|
53
|
+
args.should == 'snapurl file:///1/2/html/snapshot-001.html --no-thumbnail --no-clip --filename snapshot-001 --output-dir /1/2'
|
54
|
+
end
|
55
|
+
@session.screenshot('/1/2', 'snapshot-001')
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should embed image' do
|
59
|
+
@session.should_receive(:embed).with('/1/2/snapshot-001.png', 'image/png')
|
60
|
+
@session.screenshot('/1/2', 'snapshot-001')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should set response_body_for_last_screenshot' do
|
64
|
+
lambda { @session.screenshot('/1/2', 'snapshot-001') }.should change(@session, :response_body_for_last_screenshot).to('response html')
|
32
65
|
end
|
33
|
-
end
|
34
66
|
|
35
|
-
|
67
|
+
describe 'when snapurl fails' do
|
68
|
+
before(:each) do
|
69
|
+
@session.stub!(:'`').and_return { |args| `ruby -e 'exit(1)'` }
|
70
|
+
@session.stub!(:report_error_running_screenshot_command)
|
71
|
+
end
|
36
72
|
|
73
|
+
it 'should not embed image' do
|
74
|
+
@session.should_not_receive(:embed)
|
75
|
+
@session.screenshot('/1/2', 'snapshot-001')
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should not set response_body_for_last_screenshot' do
|
79
|
+
lambda { @session.screenshot('/1/2', 'snapshot-001') }.should_not change(@session, :response_body_for_last_screenshot)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should call report_error_running_screenshot_command' do
|
83
|
+
@session.should_receive(:report_error_running_screenshot_command)
|
84
|
+
@session.screenshot('/1/2', 'snapshot-001')
|
85
|
+
end
|
86
|
+
end
|
37
87
|
end
|
38
88
|
|
39
89
|
describe 'protected' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-screenshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: universal-darwin
|
6
6
|
authors:
|
7
7
|
- Joel Chippindale
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-01 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -18,9 +18,9 @@ dependencies:
|
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- - "
|
21
|
+
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.4.
|
23
|
+
version: 0.4.3
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: webrat
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
version_requirement:
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.5.3
|
34
34
|
version:
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: 0.0.3
|
44
44
|
version:
|
45
|
-
description: Cucumber (http://cukes.info/)
|
45
|
+
description: Extension for Cucumber (http://cukes.info/) that makes it easy to use Webkit to capture PNG screenshots of your web application during tests
|
46
46
|
email: joel.chippindale@gmail.com
|
47
47
|
executables: []
|
48
48
|
|
@@ -57,14 +57,12 @@ files:
|
|
57
57
|
- Rakefile
|
58
58
|
- VERSION.yml
|
59
59
|
- lib/cucumber_screenshot.rb
|
60
|
-
- lib/cucumber_screenshot/extensions.rb
|
61
60
|
- lib/cucumber_screenshot/world.rb
|
62
|
-
- spec/cucumber_screenshot/extensions_spec.rb
|
63
61
|
- spec/cucumber_screenshot/world_spec.rb
|
64
62
|
- spec/spec.opts
|
65
63
|
- spec/spec_helper.rb
|
66
64
|
has_rdoc: true
|
67
|
-
homepage:
|
65
|
+
homepage: http://github.com/mocoso/cucumber-screenshot
|
68
66
|
licenses: []
|
69
67
|
|
70
68
|
post_install_message:
|
@@ -91,8 +89,7 @@ rubyforge_project:
|
|
91
89
|
rubygems_version: 1.3.5
|
92
90
|
signing_key:
|
93
91
|
specification_version: 3
|
94
|
-
summary: Cucumber
|
92
|
+
summary: Extension for Cucumber to capture PNG screenshots of your app
|
95
93
|
test_files:
|
96
|
-
- spec/cucumber_screenshot/extensions_spec.rb
|
97
94
|
- spec/cucumber_screenshot/world_spec.rb
|
98
95
|
- spec/spec_helper.rb
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module CucumberScreenshot
|
2
|
-
module Extensions
|
3
|
-
|
4
|
-
module StepMother
|
5
|
-
def self.included(base)
|
6
|
-
unless base.method_defined?(:embed_image)
|
7
|
-
base.send(:define_method, :embed_image) do |image_path|
|
8
|
-
@visitor.embed_image(image_path)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module TreeWalker
|
15
|
-
def self.included(base)
|
16
|
-
unless base.method_defined?(:embed_image)
|
17
|
-
base.send(:define_method, :embed_image) do |image_path|
|
18
|
-
broadcast(image_path)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module Console
|
25
|
-
def self.included(base)
|
26
|
-
unless base.method_defined?(:embed_image)
|
27
|
-
base.send(:define_method, :embed_image) do |image_path|
|
28
|
-
announce("- Image saved to #{image_path}")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
module Html
|
35
|
-
def self.included(base)
|
36
|
-
unless base.method_defined?(:embed_image)
|
37
|
-
# TODO: needs style
|
38
|
-
# TODO: Place to right of or below step result (when captured with AfterStep)
|
39
|
-
base.send(:define_method, :embed_image) do |image_path|
|
40
|
-
builder.a('Screenshot', :class => 'announcement', :href => '#', :onclick => "img=document.getElementById('#{image_path}'); img.style.display = (img.style.display == 'none' ? 'block' : 'none');")
|
41
|
-
builder.img(:id => image_path, :src => image_path, :style => 'display: none')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
Cucumber::StepMother.send(:include, CucumberScreenshot::Extensions::StepMother)
|
50
|
-
|
51
|
-
Cucumber::Ast::TreeWalker.send(:include, CucumberScreenshot::Extensions::TreeWalker)
|
52
|
-
|
53
|
-
Cucumber::Formatter::Pretty.send(:include, CucumberScreenshot::Extensions::Console)
|
54
|
-
Cucumber::Formatter::Html.send(:include, CucumberScreenshot::Extensions::Html)
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe CucumberScreenshot::Extensions do
|
4
|
-
|
5
|
-
describe 'formatters' do
|
6
|
-
before(:each) do
|
7
|
-
@step_mother = mock('step_mother')
|
8
|
-
@io = mock('io')
|
9
|
-
end
|
10
|
-
|
11
|
-
describe 'Pretty#embed_image' do
|
12
|
-
it 'should call announce' do
|
13
|
-
formatter = Cucumber::Formatter::Pretty.new(@step_mother, @io, {})
|
14
|
-
formatter.should_receive(:announce).with('- Image saved to /tmp/foo.png')
|
15
|
-
formatter.embed_image('/tmp/foo.png')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'Html#embed_image' do
|
20
|
-
it 'should build link and image' do
|
21
|
-
formatter = Cucumber::Formatter::Html.new(@step_mother, @io, {})
|
22
|
-
builder = mock('builder')
|
23
|
-
formatter.stub!(:builder => builder)
|
24
|
-
builder.should_receive(:a)
|
25
|
-
builder.should_receive(:img)
|
26
|
-
formatter.embed_image('/tmp/foo.png')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|