gnawrnip 0.0.4 → 0.1.0
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/Gemfile +1 -0
- data/example/spec/features/hello.feature +39 -5
- data/example/spec/spec_helper.rb +2 -0
- data/example/spec/steps/hello_steps.rb +15 -0
- data/example/web.rb +26 -0
- data/gnawrnip.gemspec +1 -1
- data/lib/gnawrnip/ext/capybara/session.rb +10 -12
- data/lib/gnawrnip/no_screenshot.png +0 -0
- data/lib/gnawrnip/rspec.rb +1 -3
- data/lib/gnawrnip/screenshot.rb +1 -1
- data/lib/gnawrnip/step_screenshot.rb +73 -10
- data/lib/gnawrnip/version.rb +1 -1
- data/spec/gnawrnip/rspec_spec.rb +5 -1
- data/spec/gnawrnip/screenshot_spec.rb +1 -1
- data/spec/gnawrnip/step_screenshot_spec.rb +28 -3
- metadata +5 -4
data/Gemfile
CHANGED
@@ -1,27 +1,61 @@
|
|
1
1
|
Feature: Access
|
2
2
|
|
3
|
-
Scenario: / (
|
3
|
+
Scenario: / (SUCCESS)
|
4
4
|
When I am on the "/"
|
5
5
|
Then I should see "Hello World"
|
6
6
|
|
7
|
-
Scenario: / (
|
7
|
+
Scenario: / (FAILED)
|
8
8
|
When I am on the "/"
|
9
9
|
Then I should see "Hoge World"
|
10
10
|
|
11
|
-
Scenario: /form (
|
11
|
+
Scenario: /form (SUCCESS)
|
12
12
|
When I am on the "/form"
|
13
13
|
And type "Gongo" to "name"
|
14
14
|
And click "Go!"
|
15
15
|
Then I should see "Gongo"
|
16
16
|
|
17
|
-
Scenario: /form (
|
17
|
+
Scenario: /form (FAILED)
|
18
18
|
When I am on the "/form"
|
19
19
|
And type "Gongo" to "name"
|
20
20
|
And click "Go!"
|
21
21
|
Then I should see "Gengo"
|
22
22
|
|
23
|
-
Scenario: /form (
|
23
|
+
Scenario: /form (FAILED)
|
24
24
|
When I am on the "/form"
|
25
25
|
And type "Gongo" to "name"
|
26
26
|
And click "Push"
|
27
27
|
Then I should see "Gongo"
|
28
|
+
|
29
|
+
@javascript
|
30
|
+
Scenario: /confirm (SUCCESS) (confirm 'ok' using selenium)
|
31
|
+
When I am on the "/confirm"
|
32
|
+
And type "Gongo" to "name"
|
33
|
+
And click "Go!"
|
34
|
+
And "submit?" confirm is "ok"
|
35
|
+
Then I should see "Gongo"
|
36
|
+
|
37
|
+
@javascript
|
38
|
+
Scenario: /confirm (SUCCESS) (confirm 'cancel' using selenium)
|
39
|
+
When I am on the "/confirm"
|
40
|
+
And type "Gongo" to "name"
|
41
|
+
And click "Go!"
|
42
|
+
And "submit?" confirm is "cancel"
|
43
|
+
Then I should not see "Gongo"
|
44
|
+
And typed "name" with "Gongo"
|
45
|
+
|
46
|
+
@javascript
|
47
|
+
Scenario: /confirm (FAILED) (confirm 'ok' using selenium)
|
48
|
+
When I am on the "/confirm"
|
49
|
+
And type "Gongo" to "name"
|
50
|
+
And click "Go!"
|
51
|
+
And "submit?" confirm is "ok"
|
52
|
+
Then I should see "Gengo"
|
53
|
+
|
54
|
+
@javascript
|
55
|
+
Scenario: /confirm (FAILED) (confirm 'cancel' using selenium)
|
56
|
+
When I am on the "/confirm"
|
57
|
+
And type "Gongo" to "name"
|
58
|
+
And click "Go!"
|
59
|
+
And "submit?" confirm is "cancel"
|
60
|
+
Then I should not see "Gongo"
|
61
|
+
And typed "name" with "Gengo"
|
data/example/spec/spec_helper.rb
CHANGED
@@ -6,10 +6,25 @@ step 'I should see :text' do |text|
|
|
6
6
|
expect(page).to have_content(text)
|
7
7
|
end
|
8
8
|
|
9
|
+
step 'I should not see :text' do |text|
|
10
|
+
expect(page).not_to have_content(text)
|
11
|
+
end
|
12
|
+
|
9
13
|
step 'type :text to :field' do |text, field|
|
10
14
|
fill_in field, with: text
|
11
15
|
end
|
12
16
|
|
17
|
+
step 'typed :field with :text' do |field, text|
|
18
|
+
expect(page).to have_field(field, with: text)
|
19
|
+
end
|
20
|
+
|
13
21
|
step 'click :button' do |button|
|
14
22
|
click_button button
|
15
23
|
end
|
24
|
+
|
25
|
+
step ':text confirm is :choice' do |text, choice|
|
26
|
+
dialog = page.driver.browser.switch_to.alert
|
27
|
+
expect(dialog.text).to eq text
|
28
|
+
|
29
|
+
choice == 'ok' ? dialog.accept : dialog.dismiss
|
30
|
+
end
|
data/example/web.rb
CHANGED
@@ -13,6 +13,14 @@ post '/result' do
|
|
13
13
|
erb :index
|
14
14
|
end
|
15
15
|
|
16
|
+
get '/confirm' do
|
17
|
+
erb :confirm
|
18
|
+
end
|
19
|
+
|
20
|
+
post '/result_confirm' do
|
21
|
+
erb :confirm
|
22
|
+
end
|
23
|
+
|
16
24
|
|
17
25
|
__END__
|
18
26
|
|
@@ -33,3 +41,21 @@ __END__
|
|
33
41
|
</form>
|
34
42
|
</body>
|
35
43
|
</html>
|
44
|
+
|
45
|
+
@@ confirm
|
46
|
+
<!DOCTYPE html>
|
47
|
+
<html>
|
48
|
+
<head>
|
49
|
+
<style>
|
50
|
+
body { background-color: #aaaaaa; }
|
51
|
+
div#result { color: red; }
|
52
|
+
</style>
|
53
|
+
</head>
|
54
|
+
<body>
|
55
|
+
<div id="result"><%= params[:name] %></div>
|
56
|
+
<form method="POST" action="/result_confirm">
|
57
|
+
<label>Name: <input type="text" name="name"></label>
|
58
|
+
<input type="submit" value="Go!" onclick="return confirm('submit?');" />
|
59
|
+
</form>
|
60
|
+
</body>
|
61
|
+
</html>
|
data/gnawrnip.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency 'capybara', "~> 2.1"
|
22
|
-
spec.add_dependency 'turnip_formatter', '~> 0.
|
22
|
+
spec.add_dependency 'turnip_formatter', '~> 0.2.0'
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
spec.add_development_dependency 'rspec'
|
@@ -2,19 +2,17 @@ require 'capybara/session'
|
|
2
2
|
|
3
3
|
module Capybara
|
4
4
|
class Session
|
5
|
-
SAVE_SCREENSHOT_METHODS = [
|
6
|
-
:
|
7
|
-
:click_link, :fill_in, :select, :uncheck, :unselect, :click_on,
|
8
|
-
:evaluate_script, :visit
|
5
|
+
SAVE_SCREENSHOT_METHODS = NODE_METHODS + [
|
6
|
+
:visit, :has_title?, :has_no_title?
|
9
7
|
]
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
SAVE_SCREENSHOT_METHODS.each do |method|
|
10
|
+
alias_method "after_hook_#{method}".to_sym, method
|
11
|
+
|
12
|
+
define_method method do |*args, &block|
|
13
|
+
Gnawrnip::Animation.add_frame
|
14
|
+
send("after_hook_#{method}", *args, &block)
|
15
|
+
end
|
16
|
+
end
|
19
17
|
end
|
20
18
|
end
|
Binary file
|
data/lib/gnawrnip/rspec.rb
CHANGED
@@ -10,9 +10,7 @@ RSpec.configure do |config|
|
|
10
10
|
config.after(:each, turnip: true) do
|
11
11
|
if example.exception
|
12
12
|
example.metadata[:gnawrnip] = {}
|
13
|
-
|
14
|
-
# example.metadata[:gnawrnip][:screenshot] = Gnawrnip::Animation.generate
|
15
|
-
example.metadata[:gnawrnip][:screenshot] = Gnawrnip::Screenshot.take
|
13
|
+
example.metadata[:gnawrnip][:screenshot] = Gnawrnip::Animation.frames.compact
|
16
14
|
end
|
17
15
|
end
|
18
16
|
end
|
data/lib/gnawrnip/screenshot.rb
CHANGED
@@ -1,19 +1,82 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'turnip_formatter/template'
|
1
3
|
require 'turnip_formatter/step/failure'
|
2
4
|
|
3
5
|
module Gnawrnip
|
4
6
|
module StepScreenshot
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
class << self
|
8
|
+
#
|
9
|
+
# @param [Array] png_base64_list array of base64 encoded image
|
10
|
+
#
|
11
|
+
def build(png_base64_list)
|
12
|
+
case png_base64_list.length
|
13
|
+
when 0
|
14
|
+
description_no_screenshot
|
15
|
+
when 1
|
16
|
+
still_image(png_base64_list.first)
|
17
|
+
else
|
18
|
+
animation_image(png_base64_list)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def description_no_screenshot
|
23
|
+
@no_screenshot ||= description_frame(:no_screenshot)
|
24
|
+
still_image(@no_screenshot)
|
25
|
+
end
|
26
|
+
|
27
|
+
def animation_image(images)
|
28
|
+
text = '<div class="screenshot animation">'
|
29
|
+
text += images.map { |data| img_tag(data) }.join
|
30
|
+
text + '</div>'
|
31
|
+
end
|
32
|
+
|
33
|
+
def still_image(data)
|
34
|
+
'<div class="screenshot">' + img_tag(data) + '</div>'
|
35
|
+
end
|
36
|
+
|
37
|
+
def img_tag(data)
|
38
|
+
'<img src="data:image/png;base64,' + data + '"/>'
|
39
|
+
end
|
40
|
+
|
41
|
+
def description_frame(scene)
|
42
|
+
path = File.dirname(__FILE__) + "/#{scene.to_s}.png"
|
43
|
+
Base64.strict_encode64(File.read(path))
|
44
|
+
end
|
13
45
|
end
|
14
46
|
end
|
15
47
|
end
|
16
48
|
|
17
|
-
TurnipFormatter
|
18
|
-
|
49
|
+
module TurnipFormatter
|
50
|
+
Template.add_scss(<<-EOS)
|
51
|
+
div#steps-statistics section.scenario {
|
52
|
+
ul.steps {
|
53
|
+
div.screenshot {
|
54
|
+
> img {
|
55
|
+
width: 90%;
|
56
|
+
border: 2px solid black;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
EOS
|
62
|
+
|
63
|
+
Template.add_js(<<-EOS)
|
64
|
+
$(function() {
|
65
|
+
$('.screenshot.animation').each(function() {
|
66
|
+
var imgs = $(this).children('img');
|
67
|
+
var frame = 0;
|
68
|
+
|
69
|
+
imgs.hide();
|
70
|
+
setInterval(function() {
|
71
|
+
imgs.hide();
|
72
|
+
imgs.eq(frame).show();
|
73
|
+
frame = (++frame % imgs.length);
|
74
|
+
}, 1000);
|
75
|
+
});
|
76
|
+
});
|
77
|
+
EOS
|
78
|
+
|
79
|
+
Step::Failure.add_template Gnawrnip::StepScreenshot do
|
80
|
+
example.metadata[:gnawrnip][:screenshot] || []
|
81
|
+
end
|
19
82
|
end
|
data/lib/gnawrnip/version.rb
CHANGED
data/spec/gnawrnip/rspec_spec.rb
CHANGED
@@ -15,13 +15,17 @@ module Gnawrnip
|
|
15
15
|
example
|
16
16
|
end
|
17
17
|
|
18
|
+
before do
|
19
|
+
Gnawrnip::Animation.stub(:frames) { ['aiueo', nil, 'lllll'] }
|
20
|
+
end
|
21
|
+
|
18
22
|
context '"turnip" spec group' do
|
19
23
|
let(:group) do
|
20
24
|
::RSpec::Core::ExampleGroup.describe('Feature', turnip: true)
|
21
25
|
end
|
22
26
|
|
23
27
|
it 'should save screen shot at error' do
|
24
|
-
expect(example.metadata[:gnawrnip][:screenshot]).to eq
|
28
|
+
expect(example.metadata[:gnawrnip][:screenshot]).to eq ['aiueo', 'lllll']
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
@@ -8,12 +8,37 @@ module Gnawrnip
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'exists failure step template' do
|
11
|
-
expect(TurnipFormatter::Step::Failure.templates).to have_key
|
11
|
+
expect(TurnipFormatter::Step::Failure.templates).to have_key template
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '.build' do
|
15
|
-
subject { template.build(
|
16
|
-
|
15
|
+
subject { template.build(data_list) }
|
16
|
+
|
17
|
+
context 'has multiple data' do
|
18
|
+
let(:data_list) { ['aiueo', '12345', 'abcde'] }
|
19
|
+
it {
|
20
|
+
should include '<div class="screenshot animation">'
|
21
|
+
should include '<img src="data:image/png;base64,aiueo"/>'
|
22
|
+
should include '<img src="data:image/png;base64,12345"/>'
|
23
|
+
should include '<img src="data:image/png;base64,abcde"/></div>'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'has single data' do
|
28
|
+
let(:data_list) { ['aiueo'] }
|
29
|
+
it {
|
30
|
+
should include '<div class="screenshot">'
|
31
|
+
should include '<img src="data:image/png;base64,aiueo"/></div>'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'has no data' do
|
36
|
+
let(:data_list) { [] }
|
37
|
+
it {
|
38
|
+
should include '<div class="screenshot">'
|
39
|
+
should include '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAhQ'
|
40
|
+
}
|
41
|
+
end
|
17
42
|
end
|
18
43
|
end
|
19
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gnawrnip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
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: 2013-06-
|
12
|
+
date: 2013-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capybara
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.
|
37
|
+
version: 0.2.0
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
45
|
+
version: 0.2.0
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: bundler
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- lib/gnawrnip.rb
|
132
132
|
- lib/gnawrnip/animation.rb
|
133
133
|
- lib/gnawrnip/ext/capybara/session.rb
|
134
|
+
- lib/gnawrnip/no_screenshot.png
|
134
135
|
- lib/gnawrnip/rspec.rb
|
135
136
|
- lib/gnawrnip/screenshot.rb
|
136
137
|
- lib/gnawrnip/step_screenshot.rb
|