gnawrnip 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e87b1143d22ee0a5d40c9d1a3e8d97e613cd98a
4
- data.tar.gz: 0f1019fa5cdee6d965cd05102973319ad9071334
3
+ metadata.gz: 6af6f42bf91fd705297fbffe6ae646ab12b61f34
4
+ data.tar.gz: b63314cda20223f47b9085b9ce6812f77b131b56
5
5
  SHA512:
6
- metadata.gz: 34088780441f5712484d8c9ff362ea0413edf02ce4caa36e00fdd75ed9831cc0d72cc967585eba0a75d74add781806d66d503fc64731b5e0747a697210283755
7
- data.tar.gz: 148e19c2a82d6906433ecc91445fb93e45159f7cee3421234632003a0c916ff7a520842593c3131a5ac319aed1b9ddc917171ef4698400dc8df0af4ccdd34868
6
+ metadata.gz: 79aec3026d063787269ba122e935eb42c22aa5ac174c65e1328700f82d29bc62d35a62620a3f76024a803ca55734271724e48bf9a2555fa9a43870ada44fe2ab
7
+ data.tar.gz: 544a546b864326be38eff60454eea7b83aaba559ac5656de9535ce1c7817922aedd315afffc84db0c39bf18f0e6cd74d0d6ecfb5f241947c85b2704e0c31aa2b
data/.travis.yml CHANGED
@@ -4,3 +4,8 @@ rvm:
4
4
  - 2.0.0
5
5
  - 2.1.0
6
6
  script: bundle exec rspec
7
+ gemfile:
8
+ - spec/gemfiles/Gemfile-rspec-2.14.x
9
+ - spec/gemfiles/Gemfile-rspec-2.99.x
10
+ - spec/gemfiles/Gemfile-rspec-3.0.x
11
+
data/README.md CHANGED
@@ -49,15 +49,12 @@ You can do to customize a screenshot.
49
49
 
50
50
  ```ruby
51
51
  Gnawrnip.configure do |c|
52
- c.frame_interval_ms = 1000 # milliseconds
53
52
  c.make_animation = true
54
53
  c.max_frame_size = 1024 # pixel
55
54
  end
56
55
  ```
57
56
 
58
57
  * `make_animation` (Boolean) Whether to make animation GIF. (Default: true)
59
- * `frame_interval_ms` (Integer) A time (millisecond) between each image in an animation. Default is `1000`.
60
- * This option is enabled only when the `make_animation = true`.
61
58
  * `max_frame_size` (Integer) Maximum size that use to resize of image.
62
59
  * If given, it resize the image to fit to this value.
63
60
  * Ignored if this value is greater than original width and height.
@@ -21,7 +21,6 @@ Capybara.default_driver = :poltergeist
21
21
  Capybara.javascript_driver = :selenium
22
22
 
23
23
  Gnawrnip.configure do |c|
24
- c.frame_interval_ms = 200
25
- c.make_animation = true
26
- c.max_frame_size = 1024 # pixel
24
+ c.make_animation = true
25
+ c.max_frame_size = 1024 # pixel
27
26
  end
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.2"
22
- spec.add_dependency 'turnip_formatter', '~> 0.2.11'
22
+ spec.add_dependency 'turnip_formatter', '~> 0.3.0'
23
23
  spec.add_dependency 'oily_png'
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
@@ -42,7 +42,7 @@ module Gnawrnip
42
42
  new_height = target / ratio
43
43
  end
44
44
 
45
- return [new_width, new_height]
45
+ [new_width, new_height]
46
46
  end
47
47
  end
48
48
  end
@@ -0,0 +1,48 @@
1
+ $(function() {
2
+ $('.screenshot.animation').each(function() {
3
+ var slide = $(this).find('.slides').cycle({
4
+ timeout: 1000,
5
+ autoHeight: "calc",
6
+ pager: $(this).find('div.nav .pager')
7
+ });
8
+
9
+ var nav = $(this).find('div.nav');
10
+ var playButton = nav.find('.play');
11
+ var pauseButton = nav.find('.pause');
12
+ var prevButton = nav.find('.prev');
13
+ var nextButton = nav.find('.next');
14
+
15
+ var setPauseManipulate = function() {
16
+ playButton.show();
17
+ pauseButton.hide();
18
+ prevButton.show();
19
+ nextButton.show();
20
+ };
21
+
22
+ var setPlayManipulate = function() {
23
+ playButton.hide();
24
+ pauseButton.show();
25
+ prevButton.hide();
26
+ nextButton.hide();
27
+ };
28
+
29
+ playButton.click(function() { slide.cycle('resume'); });
30
+ pauseButton.click(function() { slide.cycle('pause'); });
31
+ prevButton.click(function() { slide.cycle('prev'); });
32
+ nextButton.click(function() { slide.cycle('next'); });
33
+
34
+ setPlayManipulate();
35
+
36
+ slide.on('cycle-pager-activated', function(event, opts) {
37
+ slide.cycle('pause');
38
+ });
39
+
40
+ slide.on('cycle-paused', function(event, opts) {
41
+ setPauseManipulate();
42
+ });
43
+
44
+ slide.on('cycle-resumed', function(event, opts) {
45
+ setPlayManipulate();
46
+ });
47
+ });
48
+ });
@@ -0,0 +1,47 @@
1
+ div#steps-statistics section.scenario {
2
+ div.steps {
3
+ div.screenshot {
4
+ img {
5
+ max-width: 90%;
6
+ border: 2px solid black;
7
+ }
8
+ }
9
+
10
+ div.screenshot.animation {
11
+ > div.nav {
12
+ text-align: center;
13
+
14
+ .pager {
15
+ margin-left: auto;
16
+ margin-right: auto;
17
+
18
+ span {
19
+ font-size: 50px;
20
+ display: inline;
21
+ color: #999999;
22
+ cursor: pointer;
23
+
24
+ &.cycle-pager-active {
25
+ color: red;
26
+ }
27
+ }
28
+ }
29
+
30
+ .manipulate {
31
+ margin-bottom: 1em;
32
+
33
+ i {
34
+ color: black;
35
+ cursor: pointer;
36
+ margin-left: 0.3em;
37
+ margin-right: 0.3em;
38
+
39
+ &:hover {
40
+ color: #aa0000;
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
@@ -1,15 +1,24 @@
1
+ require 'fileutils'
1
2
  require 'oily_png'
2
3
 
3
4
  module Gnawrnip
4
5
  class Image
5
6
  #
6
- # @parma [File] Screenshot image file (png)
7
+ # @parma [String] filepath Screenshot image filepath
7
8
  #
8
- def initialize(file)
9
- @file = file
9
+ def initialize(filepath)
10
+ @filepath = filepath
10
11
  analysis
11
12
  end
12
13
 
14
+ def to_html(format = :png)
15
+ width = width
16
+ height = height
17
+ src = "data:image/#{format};base64,#{to_base64}"
18
+
19
+ %Q(<img width="#{width}" height="#{height}" src="#{src}"/>)
20
+ end
21
+
13
22
  #
14
23
  # @return [Fixnum] Width of image
15
24
  #
@@ -25,18 +34,14 @@ module Gnawrnip
25
34
  end
26
35
 
27
36
  def to_base64
28
- Base64.strict_encode64(File.read(@file.path))
37
+ Base64.strict_encode64(File.read(@filepath))
29
38
  end
30
39
 
31
40
  def resize(width, height)
32
- canvas.resample_bilinear(width, height).save(@file.path)
41
+ canvas.resample_bilinear(width, height).save(@filepath)
33
42
  analysis
34
43
  end
35
44
 
36
- def close!
37
- @file.close!
38
- end
39
-
40
45
  private
41
46
 
42
47
  #
@@ -47,7 +52,7 @@ module Gnawrnip
47
52
  end
48
53
 
49
54
  def canvas
50
- OilyPNG::Canvas.from_file(@file)
55
+ OilyPNG::Canvas.from_file(@filepath)
51
56
  end
52
57
  end
53
58
  end
@@ -10,14 +10,6 @@ module Gnawrnip
10
10
  frames.clear
11
11
  end
12
12
 
13
- #
14
- # Close tempfiles.
15
- #
16
- def discard!
17
- frames.compact.each(&:close!)
18
- reset!
19
- end
20
-
21
13
  def frames
22
14
  @frames ||= []
23
15
  end
@@ -5,6 +5,10 @@ RSpec.configure do |config|
5
5
  Gnawrnip.ready!
6
6
  end
7
7
 
8
+ config.after(:all) do
9
+ Gnawrnip.finish!
10
+ end
11
+
8
12
  # https://github.com/jnicklas/capybara/blob/master/lib/capybara/rspec.rb
9
13
  fetch_current_example = RSpec.respond_to?(:current_example) ?
10
14
  proc { RSpec.current_example } : proc { |context| context.example }
@@ -22,8 +26,6 @@ RSpec.configure do |config|
22
26
  Gnawrnip.photographer.take_shot
23
27
  screenshots = Gnawrnip.photographer.frames.compact
24
28
  example.metadata[:gnawrnip][:screenshot] = screenshots
25
- else
26
- Gnawrnip.photographer.discard!
27
29
  end
28
30
  end
29
31
  end
@@ -1,12 +1,11 @@
1
- require 'tempfile'
2
1
  require 'time'
3
2
  require 'capybara'
4
- require 'gnawrnip/developer'
3
+ require 'securerandom'
4
+ require 'fileutils'
5
5
 
6
6
  module Gnawrnip
7
7
  class Screenshot
8
8
  class << self
9
-
10
9
  #
11
10
  # Screenshot of current capybara session
12
11
  #
@@ -22,7 +21,7 @@ module Gnawrnip
22
21
  #
23
22
  #
24
23
  # @param [Fixnum] wait_second Second to repeat the retry
25
- # @return [Tempfile] Image file of screenshot
24
+ # @return [String] Image filename of screenshot
26
25
  #
27
26
  def take(wait_second = Capybara.default_wait_time)
28
27
  start_time = Time.now
@@ -44,20 +43,25 @@ module Gnawrnip
44
43
  end
45
44
  end
46
45
 
47
- private
46
+ def session
47
+ Capybara.current_session
48
+ end
48
49
 
49
- def session
50
- Capybara.current_session
51
- end
50
+ #
51
+ # @return [Gnawrnip::Image]
52
+ #
53
+ def shot
54
+ path = filepath
52
55
 
53
- #
54
- # @return [Gnawrnip::Image]
55
- #
56
- def shot
57
- tempfile = Tempfile.new(['gnawrnip', '.png'])
58
- session.save_screenshot(tempfile.path)
59
- Developer.new.develop(tempfile)
60
- end
56
+ FileUtils.touch(path)
57
+ session.save_screenshot(path)
58
+
59
+ path
60
+ end
61
+
62
+ def filepath
63
+ SCREENSHOT_OUTPUT_DIR + '/gnawrnip-' + SecureRandom.uuid + '.png'
64
+ end
61
65
  end
62
66
  end
63
67
  end
@@ -1,26 +1,32 @@
1
1
  require 'base64'
2
- require 'turnip_formatter/template'
3
- require 'turnip_formatter/step/failure'
2
+ require 'turnip_formatter/step_template/exception'
3
+ require 'gnawrnip/developer'
4
4
 
5
5
  module Gnawrnip
6
- module StepScreenshot
7
- class << self
8
- #
9
- # @param [Array] images array of Gnawrnip::Image
10
- #
11
- def build(images)
12
- case images.length
13
- when 0
14
- ''
15
- when 1
16
- single_image(images.first)
17
- else
18
- animation_image(images)
19
- end
6
+ class StepScreenshot < TurnipFormatter::StepTemplate::Exception
7
+ on_failed :build
8
+
9
+ def self.scss
10
+ File.read(File.dirname(__FILE__) + '/gnawrnip.scss')
11
+ end
12
+
13
+ def build(example)
14
+ images = example.metadata[:gnawrnip][:screenshot]
15
+
16
+ case images.length
17
+ when 0
18
+ ''
19
+ when 1
20
+ single_image(images.first)
21
+ else
22
+ animation_image(images)
20
23
  end
24
+ end
25
+
26
+ private
21
27
 
22
- def animation_image(paths)
23
- text = <<-EOS
28
+ def animation_image(paths)
29
+ text = <<-EOS
24
30
  <div class="screenshot animation">
25
31
  <div class="nav">
26
32
  <div class="pager"></div>
@@ -33,128 +39,35 @@ module Gnawrnip
33
39
  </div>
34
40
  <div class="slides">
35
41
  EOS
36
- text += Gnawrnip.publisher.animation(paths)
37
- text + <<-EOS
42
+ text += develop(paths)
43
+ text + <<-EOS
38
44
  </div>
39
45
  </div>
40
46
  EOS
41
- end
42
-
43
- def single_image(path)
44
- text = '<div class="screenshot">'
45
- text += Gnawrnip.publisher.single(path)
46
- text + '</div>'
47
- end
48
47
  end
49
- end
50
- end
51
-
52
- module TurnipFormatter
53
- Template.add_js_file('http://cdnjs.cloudflare.com/ajax/libs/jquery.cycle2/20130801/jquery.cycle2.min.js')
54
- Template.add_css_file('http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css')
55
-
56
- Template.add_js(<<-EOS)
57
- $(function() {
58
- $('.screenshot.animation').each(function() {
59
- var slide = $(this).find('.slides').cycle({
60
- timeout: #{Gnawrnip.frame_interval_ms},
61
- autoHeight: "calc",
62
- pager: $(this).find('div.nav .pager')
63
- });
64
-
65
- var nav = $(this).find('div.nav');
66
- var playButton = nav.find('.play');
67
- var pauseButton = nav.find('.pause');
68
- var prevButton = nav.find('.prev');
69
- var nextButton = nav.find('.next');
70
-
71
- var setPauseManipulate = function() {
72
- playButton.show();
73
- pauseButton.hide();
74
- prevButton.show();
75
- nextButton.show();
76
- };
77
-
78
- var setPlayManipulate = function() {
79
- playButton.hide();
80
- pauseButton.show();
81
- prevButton.hide();
82
- nextButton.hide();
83
- };
84
48
 
85
- playButton.click(function() { slide.cycle('resume'); });
86
- pauseButton.click(function() { slide.cycle('pause'); });
87
- prevButton.click(function() { slide.cycle('prev'); });
88
- nextButton.click(function() { slide.cycle('next'); });
89
-
90
- setPlayManipulate();
91
-
92
- slide.on('cycle-pager-activated', function(event, opts) {
93
- slide.cycle('pause');
94
- });
95
-
96
- slide.on('cycle-paused', function(event, opts) {
97
- setPauseManipulate();
98
- });
99
-
100
- slide.on('cycle-resumed', function(event, opts) {
101
- setPlayManipulate();
102
- });
103
- });
104
- });
105
- EOS
106
-
107
- Template.add_scss(<<-EOS)
108
- div#steps-statistics section.scenario {
109
- ul.steps {
110
- div.screenshot {
111
- img {
112
- max-width: 90%;
113
- border: 2px solid black;
114
- }
115
- }
116
-
117
- div.screenshot.animation {
118
- > div.nav {
119
- text-align: center;
120
-
121
- .pager {
122
- margin-left: auto;
123
- margin-right: auto;
124
-
125
- span {
126
- font-size: 50px;
127
- display: inline;
128
- color: #999999;
129
- cursor: pointer;
130
-
131
- &.cycle-pager-active {
132
- color: red;
133
- }
134
- }
135
- }
49
+ def single_image(path)
50
+ text = '<div class="screenshot">'
51
+ text += develop([path])
52
+ text + '</div>'
53
+ end
136
54
 
137
- .manipulate {
138
- margin-bottom: 1em;
55
+ def develop(paths)
56
+ paths.map do |path|
57
+ image = developer.develop(path)
58
+ image.to_html
59
+ end.join
60
+ end
139
61
 
140
- i {
141
- color: black;
142
- cursor: pointer;
143
- margin-left: 0.3em;
144
- margin-right: 0.3em;
62
+ def developer
63
+ @developer ||= Developer.new
64
+ end
65
+ end
66
+ end
145
67
 
146
- &:hover {
147
- color: #aa0000;
148
- }
149
- }
150
- }
151
- }
152
- }
153
- }
154
- }
155
- EOS
68
+ TurnipFormatter.configure do |c|
69
+ c.add_javascript('http://cdnjs.cloudflare.com/ajax/libs/jquery.cycle2/20130801/jquery.cycle2.min.js')
70
+ c.add_stylesheet('http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css')
156
71
 
157
- Step::Failure.add_template Gnawrnip::StepScreenshot do
158
- example.metadata[:gnawrnip][:screenshot] || []
159
- end
72
+ c.add_javascript(File.dirname(__FILE__) + '/gnawrnip.js')
160
73
  end
@@ -1,3 +1,3 @@
1
1
  module Gnawrnip
2
- VERSION = "0.2.5"
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/gnawrnip.rb CHANGED
@@ -1,15 +1,12 @@
1
1
  require "gnawrnip/version"
2
+ require 'turnip_formatter'
2
3
  require 'gnawrnip/rspec'
3
4
  require 'gnawrnip/photographer'
4
- require 'gnawrnip/publisher'
5
5
 
6
6
  module Gnawrnip
7
- class << self
8
- #
9
- # [Integer] Time (millisecond) between each image in animation
10
- #
11
- attr_accessor :frame_interval_ms
7
+ SCREENSHOT_OUTPUT_DIR = File.expand_path('./gnawrnip_tmp')
12
8
 
9
+ class << self
13
10
  #
14
11
  # [Boolean] Whether to make animation GIF
15
12
  #
@@ -38,6 +35,12 @@ module Gnawrnip
38
35
  def ready!
39
36
  require 'gnawrnip/ext/capybara/session' if animation?
40
37
  require 'gnawrnip/step_screenshot'
38
+
39
+ FileUtils.mkdir_p(SCREENSHOT_OUTPUT_DIR)
40
+ end
41
+
42
+ def finish!
43
+ FileUtils.rm_rf(SCREENSHOT_OUTPUT_DIR)
41
44
  end
42
45
 
43
46
  def animation?
@@ -48,18 +51,13 @@ module Gnawrnip
48
51
  @photographer ||= Photographer.new
49
52
  end
50
53
 
51
- def publisher
52
- @publisher ||= Publisher.new
53
- end
54
-
55
- def publisher_driver=(driver)
56
- warn "DEPRECATED: `publisher_driver` option is deprecated (not used)."
54
+ def frame_interval_ms=(_)
55
+ warn 'DEPRECATED: `frame_interval_ms` option is deprecated (not used).'
57
56
  end
58
57
  end
59
58
  end
60
59
 
61
60
  Gnawrnip.configure do |c|
62
- c.frame_interval_ms = 1000
63
61
  c.make_animation = true
64
62
  c.max_frame_size = nil
65
63
  end
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec :path => '../..'
4
+ gem 'rspec', '~> 2.14.0'
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec :path => '../..'
4
+ gem 'rspec', '~> 2.99.0'
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec :path => '../..'
4
+ gem 'rspec', '~> 3.0.0'
@@ -3,19 +3,17 @@ require 'gnawrnip/developer'
3
3
 
4
4
  module Gnawrnip
5
5
  describe Developer do
6
- let(:developer) do
7
- Developer.new
8
- end
6
+ let(:developer) { described_class.new }
9
7
 
10
8
  before do
11
- Image.any_instance.stub(:analysis)
9
+ allow_any_instance_of(Image).to receive(:analysis)
12
10
  end
13
11
 
14
12
  context 'No given Gnawrnip.max_frame_size' do
15
13
  describe '.develop' do
16
14
  before do
17
15
  Gnawrnip.max_frame_size = nil
18
- Developer.should_not_receive(:resize)
16
+ expect(Developer).not_to receive(:resize)
19
17
  end
20
18
 
21
19
  it { developer.develop(nil) }
@@ -27,9 +25,9 @@ module Gnawrnip
27
25
  describe '.develop' do
28
26
  before do
29
27
  Gnawrnip.max_frame_size = 300
30
- Image.any_instance.stub(:width).and_return(640)
31
- Image.any_instance.stub(:height).and_return(480)
32
- Image.any_instance.should_receive(:resize).with(300, 225)
28
+ allow_any_instance_of(Image).to receive(:width).and_return(640)
29
+ allow_any_instance_of(Image).to receive(:height).and_return(480)
30
+ expect_any_instance_of(Image).to receive(:resize).with(300, 225)
33
31
  end
34
32
 
35
33
  it { developer.develop(nil) }
@@ -40,9 +38,9 @@ module Gnawrnip
40
38
  describe '.develop' do
41
39
  before do
42
40
  Gnawrnip.max_frame_size = 400
43
- Image.any_instance.stub(:width).and_return(480)
44
- Image.any_instance.stub(:height).and_return(640)
45
- Image.any_instance.should_receive(:resize).with(300, 400)
41
+ allow_any_instance_of(Image).to receive(:width).and_return(480)
42
+ allow_any_instance_of(Image).to receive(:height).and_return(640)
43
+ expect_any_instance_of(Image).to receive(:resize).with(300, 400)
46
44
  end
47
45
 
48
46
  it { developer.develop(nil) }
@@ -53,9 +51,9 @@ module Gnawrnip
53
51
  describe '.develop' do
54
52
  before do
55
53
  Gnawrnip.max_frame_size = 1024
56
- Image.any_instance.stub(:width).and_return(640)
57
- Image.any_instance.stub(:height).and_return(480)
58
- Image.any_instance.should_not_receive(:resize)
54
+ allow_any_instance_of(Image).to receive(:width).and_return(640)
55
+ allow_any_instance_of(Image).to receive(:height).and_return(480)
56
+ expect_any_instance_of(Image).not_to receive(:resize)
59
57
  end
60
58
 
61
59
  it { developer.develop(nil) }
@@ -4,12 +4,12 @@ require 'gnawrnip/image'
4
4
  module Gnawrnip
5
5
  describe Image do
6
6
  before do
7
- Image.any_instance.stub(:canvas).and_return(canvas)
7
+ allow_any_instance_of(Image).to receive(:canvas).and_return(canvas)
8
8
  end
9
9
 
10
10
  let(:image) do
11
11
  Image.new(GnawrnipTest.image('gnawrnip/image'))
12
- end
12
+ end
13
13
 
14
14
  context 'image size is 640x480' do
15
15
  let(:canvas) do
@@ -33,12 +33,12 @@ module Gnawrnip
33
33
  describe '.resize' do
34
34
  let(:canvas) do
35
35
  canvas = super()
36
- canvas.should_receive(:resample_bilinear).with(320, 240).and_return(canvas)
36
+ expect(canvas).to receive(:resample_bilinear).with(320, 240).and_return(canvas)
37
37
  canvas
38
38
  end
39
39
 
40
40
  before do
41
- Image.any_instance.should_receive(:analysis).twice
41
+ expect_any_instance_of(Image).to receive(:analysis).twice
42
42
  end
43
43
 
44
44
  it { image.resize(320, 240) }
@@ -3,12 +3,10 @@ require 'gnawrnip/photographer'
3
3
 
4
4
  module Gnawrnip
5
5
  describe Photographer do
6
- let(:photographer) do
7
- Photographer.new
8
- end
6
+ let(:photographer) { described_class.new }
9
7
 
10
8
  before do
11
- Screenshot.stub(:take).and_return('foo')
9
+ allow(Screenshot).to receive(:take).and_return('foo')
12
10
  photographer.reset!
13
11
  photographer.take_shot
14
12
  photographer.take_shot
@@ -16,8 +16,8 @@ module Gnawrnip
16
16
  end
17
17
 
18
18
  before do
19
- Gnawrnip.photographer.stub(:take_shot)
20
- Gnawrnip.photographer.stub(:frames) { ['aiueo', nil, 'lllll'] }
19
+ allow(Gnawrnip.photographer).to receive(:take_shot)
20
+ allow(Gnawrnip.photographer).to receive(:frames) { ['aiueo', nil, 'lllll'] }
21
21
  end
22
22
 
23
23
  context '"turnip" spec group' do
@@ -6,7 +6,7 @@ module Gnawrnip
6
6
  context 'Not support save_screenshot' do
7
7
  describe '.tale' do
8
8
  before do
9
- GnawrnipTest::Session.any_instance.stub(:save_screenshot) do
9
+ allow_any_instance_of(GnawrnipTest::Session).to receive(:save_screenshot) do
10
10
  raise Capybara::NotSupportedByDriverError
11
11
  end
12
12
  end
@@ -20,7 +20,7 @@ module Gnawrnip
20
20
  context 'raise unknown error' do
21
21
  describe '.take' do
22
22
  before do
23
- GnawrnipTest::Session.any_instance.stub(:save_screenshot) do
23
+ allow_any_instance_of(GnawrnipTest::Session).to receive(:save_screenshot) do
24
24
  raise Timeout::Error
25
25
  end
26
26
  end
@@ -28,7 +28,7 @@ module Gnawrnip
28
28
  context 'timeout' do
29
29
  before do
30
30
  now = Time.now
31
- Time.stub(:now).and_return(now, now + 3)
31
+ allow(Time).to receive(:now).and_return(now, now + 3)
32
32
  end
33
33
 
34
34
  it 'should raise Timeout Error' do
@@ -45,7 +45,7 @@ module Gnawrnip
45
45
  context 'success screenshot' do
46
46
  describe '.take' do
47
47
  before do
48
- Screenshot.should_receive(:shot).once
48
+ expect(Screenshot).to receive(:shot).once
49
49
  end
50
50
 
51
51
  it { Screenshot.take }
@@ -3,44 +3,39 @@ require 'gnawrnip/step_screenshot'
3
3
 
4
4
  module Gnawrnip
5
5
  describe StepScreenshot do
6
- let(:template) { StepScreenshot }
7
-
8
- it 'exists failure step template' do
9
- expect(TurnipFormatter::Step::Failure.templates).to have_key template
10
- end
6
+ let(:template) { described_class.new }
11
7
 
12
8
  describe '.build' do
13
- subject { template.build(data_list) }
9
+ before :each do
10
+ allow(template).to receive(:develop).and_return('')
11
+ end
12
+
13
+ let(:example) do
14
+ metadata = { gnawrnip: { screenshot: paths } }
15
+ double('example', metadata: metadata)
16
+ end
17
+
18
+ subject { template.build(example) }
14
19
 
15
20
  context 'has multiple data' do
16
- let(:data_list) do
17
- [
18
- double(to_base64: 'aiueo', width: 640, height: 480),
19
- double(to_base64: '12345', width: 512, height: 200),
20
- double(to_base64: 'abcde', width: 640, height: 320)
21
- ]
22
- end
21
+ let(:paths) { ['/path/to/A.png', '/path/to/B.png', '/path/to/C.png'] }
23
22
 
24
23
  it 'should get image tag and source that base64 encoded' do
25
24
  should include '<div class="screenshot animation">'
26
- should include '<img width="640" height="480" src="data:image/png;base64,aiueo"/>'
27
- should include '<img width="512" height="200" src="data:image/png;base64,12345"/>'
28
- should include '<img width="640" height="320" src="data:image/png;base64,abcde"/>'
29
25
  should include '<div class="nav">'
30
26
  end
31
27
  end
32
28
 
33
29
  context 'has single data' do
34
- let(:data_list) { [ double(to_base64: 'abcde', width: 640, height: 480) ] }
35
- it {
30
+ let(:paths) { ['/path/to/A.png'] }
31
+ it do
36
32
  should include '<div class="screenshot">'
37
- should include '<img width="640" height="480" src="data:image/png;base64,abcde"/></div>'
38
33
  should_not include '<div class="nav">'
39
- }
34
+ end
40
35
  end
41
36
 
42
37
  context 'has no data' do
43
- let(:data_list) { [] }
38
+ let(:paths) { [] }
44
39
  it { should eq '' }
45
40
  end
46
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gnawrnip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wataru MIYAGUNI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-01 00:00:00.000000000 Z
11
+ date: 2014-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.11
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.11
40
+ version: 0.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: oily_png
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -132,14 +132,18 @@ files:
132
132
  - lib/gnawrnip.rb
133
133
  - lib/gnawrnip/developer.rb
134
134
  - lib/gnawrnip/ext/capybara/session.rb
135
+ - lib/gnawrnip/gnawrnip.js
136
+ - lib/gnawrnip/gnawrnip.scss
135
137
  - lib/gnawrnip/image.rb
136
138
  - lib/gnawrnip/no_screenshot.png
137
139
  - lib/gnawrnip/photographer.rb
138
- - lib/gnawrnip/publisher.rb
139
140
  - lib/gnawrnip/rspec.rb
140
141
  - lib/gnawrnip/screenshot.rb
141
142
  - lib/gnawrnip/step_screenshot.rb
142
143
  - lib/gnawrnip/version.rb
144
+ - spec/gemfiles/Gemfile-rspec-2.14.x
145
+ - spec/gemfiles/Gemfile-rspec-2.99.x
146
+ - spec/gemfiles/Gemfile-rspec-3.0.x
143
147
  - spec/gnawrnip/developer_spec.rb
144
148
  - spec/gnawrnip/image_spec.rb
145
149
  - spec/gnawrnip/photographer_spec.rb
@@ -167,11 +171,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
171
  version: '0'
168
172
  requirements: []
169
173
  rubyforge_project:
170
- rubygems_version: 2.2.0
174
+ rubygems_version: 2.2.2
171
175
  signing_key:
172
176
  specification_version: 4
173
177
  summary: Add-on for TurnipFormatter with Capybara
174
178
  test_files:
179
+ - spec/gemfiles/Gemfile-rspec-2.14.x
180
+ - spec/gemfiles/Gemfile-rspec-2.99.x
181
+ - spec/gemfiles/Gemfile-rspec-3.0.x
175
182
  - spec/gnawrnip/developer_spec.rb
176
183
  - spec/gnawrnip/image_spec.rb
177
184
  - spec/gnawrnip/photographer_spec.rb
@@ -1,29 +0,0 @@
1
- require 'base64'
2
-
3
- module Gnawrnip
4
- class Publisher
5
-
6
- #
7
- # @params [Array] images Array of Gnawrnip::Image
8
- #
9
- def animation(images)
10
- images.map { |image| image_tag(image) }.join
11
- end
12
-
13
- #
14
- # @params [Gnawrnip::Image] image
15
- #
16
- def single(image)
17
- image_tag(image)
18
- end
19
-
20
- private
21
-
22
- def image_tag(image, format = :png)
23
- width = image.width
24
- height = image.height
25
- data = image.to_base64
26
- %Q|<img width="#{width}" height="#{height}" src="data:image/#{format.to_s};base64,#{data}"/>|
27
- end
28
- end
29
- end