gnawrnip 0.3.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6af6f42bf91fd705297fbffe6ae646ab12b61f34
4
- data.tar.gz: b63314cda20223f47b9085b9ce6812f77b131b56
3
+ metadata.gz: 28f121a332c225aa6a9be33c505ff2e8052450fb
4
+ data.tar.gz: 016797eb3184c9d0159b82e935e8f4b29ee9aff2
5
5
  SHA512:
6
- metadata.gz: 79aec3026d063787269ba122e935eb42c22aa5ac174c65e1328700f82d29bc62d35a62620a3f76024a803ca55734271724e48bf9a2555fa9a43870ada44fe2ab
7
- data.tar.gz: 544a546b864326be38eff60454eea7b83aaba559ac5656de9535ce1c7817922aedd315afffc84db0c39bf18f0e6cd74d0d6ecfb5f241947c85b2704e0c31aa2b
6
+ metadata.gz: 4fcee738f720198d3ad6716c58c1a8b2ed0af60cf09c2451385963e3b1ef376b067a28df54d1ee54e80a5144fda4f86996059c47cdd7b4ee05fb27d1a15d2d98
7
+ data.tar.gz: 842e30f5b810c1d862316027240f438b623c894743513beaac784db84568b906dda80b1d1a43bbb76c86e9948cf434deca396a6b91cb6e9350f762aa54d29aad
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ group :example do
7
7
  gem 'poltergeist'
8
8
  gem 'selenium-webdriver'
9
9
  gem 'sinatra'
10
+ gem 'tilt', '~> 1.4.1'
10
11
  end
data/example/.rspec CHANGED
@@ -1,4 +1,4 @@
1
1
  --colour
2
- -r turnip
2
+ -r turnip/rspec
3
3
  -r turnip/capybara
4
4
 
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.3.0'
22
+ spec.add_dependency 'turnip_formatter', '~> 0.3.2'
23
23
  spec.add_dependency 'oily_png'
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
@@ -46,4 +46,3 @@ module Gnawrnip
46
46
  end
47
47
  end
48
48
  end
49
-
@@ -2,15 +2,30 @@ require 'capybara/session'
2
2
 
3
3
  module Capybara
4
4
  class Session
5
- SAVE_SCREENSHOT_METHODS = NODE_METHODS + [
6
- :visit, :has_title?, :has_no_title?, :go_back, :go_forward
5
+ SAVE_SCREENSHOT_METHODS = [
6
+ :click_button,
7
+ :click_link,
8
+ :click_link_or_button,
9
+ :click_on,
10
+ :fill_in,
11
+ :choose,
12
+ :check,
13
+ :uncheck,
14
+ :select,
15
+ :unselect,
16
+ :attach_file,
17
+ :execute_script,
18
+ :go_back,
19
+ :go_forward,
20
+ :switch_to_window,
21
+ :visit
7
22
  ]
8
23
 
9
24
  SAVE_SCREENSHOT_METHODS.each do |method|
10
25
  alias_method "after_hook_#{method}".to_sym, method
11
26
 
12
27
  define_method method do |*args, &block|
13
- Gnawrnip.photographer.take_shot
28
+ Gnawrnip.photographer.take_shot if current_url != 'about:blank'
14
29
  send("after_hook_#{method}", *args, &block)
15
30
  end
16
31
  end
@@ -0,0 +1,39 @@
1
+ div#steps-statistics section.scenario div.steps div.screenshot img {
2
+ max-width: 90%;
3
+ border: 2px solid black;
4
+ }
5
+
6
+ div#steps-statistics section.scenario div.steps div.screenshot.animation > div.nav {
7
+ text-align: center;
8
+ }
9
+
10
+ div#steps-statistics section.scenario div.steps div.screenshot.animation > div.nav .pager {
11
+ margin-left: auto;
12
+ margin-right: auto;
13
+ }
14
+
15
+ div#steps-statistics section.scenario div.steps div.screenshot.animation > div.nav .pager span {
16
+ font-size: 50px;
17
+ display: inline;
18
+ color: #999999;
19
+ cursor: pointer;
20
+ }
21
+
22
+ div#steps-statistics section.scenario div.steps div.screenshot.animation > div.nav .pager span.cycle-pager-active {
23
+ color: red;
24
+ }
25
+
26
+ div#steps-statistics section.scenario div.steps div.screenshot.animation > div.nav .manipulate {
27
+ margin-bottom: 1em;
28
+ }
29
+
30
+ div#steps-statistics section.scenario div.steps div.screenshot.animation > div.nav .manipulate i {
31
+ color: black;
32
+ cursor: pointer;
33
+ margin-left: 0.3em;
34
+ margin-right: 0.3em;
35
+ }
36
+
37
+ div#steps-statistics section.scenario div.steps div.screenshot.animation > div.nav .manipulate i:hover {
38
+ color: #aa0000;
39
+ }
@@ -8,13 +8,12 @@ module Gnawrnip
8
8
  #
9
9
  def initialize(filepath)
10
10
  @filepath = filepath
11
- analysis
12
11
  end
13
12
 
14
- def to_html(format = :png)
15
- width = width
16
- height = height
17
- src = "data:image/#{format};base64,#{to_base64}"
13
+ def to_html
14
+ width = canvas.width
15
+ height = canvas.height
16
+ src = canvas.to_data_url
18
17
 
19
18
  %Q(<img width="#{width}" height="#{height}" src="#{src}"/>)
20
19
  end
@@ -23,36 +22,24 @@ module Gnawrnip
23
22
  # @return [Fixnum] Width of image
24
23
  #
25
24
  def width
26
- @dimension.width
25
+ canvas.width
27
26
  end
28
27
 
29
28
  #
30
29
  # @return [Fixnum] Height of image
31
30
  #
32
31
  def height
33
- @dimension.height
34
- end
35
-
36
- def to_base64
37
- Base64.strict_encode64(File.read(@filepath))
32
+ canvas.height
38
33
  end
39
34
 
40
35
  def resize(width, height)
41
- canvas.resample_bilinear(width, height).save(@filepath)
42
- analysis
36
+ canvas.resample_bilinear!(width, height)
43
37
  end
44
38
 
45
39
  private
46
40
 
47
- #
48
- # Update dimension (OilyPNG::Dimension) of Image
49
- #
50
- def analysis
51
- @dimension = canvas.dimension
52
- end
53
-
54
- def canvas
55
- OilyPNG::Canvas.from_file(@filepath)
56
- end
41
+ def canvas
42
+ @canvas ||= OilyPNG::Canvas.from_file(@filepath)
43
+ end
57
44
  end
58
45
  end
@@ -5,10 +5,6 @@ RSpec.configure do |config|
5
5
  Gnawrnip.ready!
6
6
  end
7
7
 
8
- config.after(:all) do
9
- Gnawrnip.finish!
10
- end
11
-
12
8
  # https://github.com/jnicklas/capybara/blob/master/lib/capybara/rspec.rb
13
9
  fetch_current_example = RSpec.respond_to?(:current_example) ?
14
10
  proc { RSpec.current_example } : proc { |context| context.example }
@@ -26,6 +22,10 @@ RSpec.configure do |config|
26
22
  Gnawrnip.photographer.take_shot
27
23
  screenshots = Gnawrnip.photographer.frames.compact
28
24
  example.metadata[:gnawrnip][:screenshot] = screenshots
25
+ else
26
+ Gnawrnip.photographer.frames.compact.each do |fp|
27
+ fp.close!
28
+ end
29
29
  end
30
30
  end
31
31
  end
@@ -1,7 +1,6 @@
1
1
  require 'time'
2
2
  require 'capybara'
3
- require 'securerandom'
4
- require 'fileutils'
3
+ require 'tempfile'
5
4
 
6
5
  module Gnawrnip
7
6
  class Screenshot
@@ -19,9 +18,8 @@ module Gnawrnip
19
18
  # @example
20
19
  # image = Gnawrnip::Screenshot.take
21
20
  #
22
- #
23
21
  # @param [Fixnum] wait_second Second to repeat the retry
24
- # @return [String] Image filename of screenshot
22
+ # @return [Tempfile] Image file of screenshot
25
23
  #
26
24
  def take(wait_second = Capybara.default_wait_time)
27
25
  start_time = Time.now
@@ -48,19 +46,13 @@ module Gnawrnip
48
46
  end
49
47
 
50
48
  #
51
- # @return [Gnawrnip::Image]
49
+ # @return [Tempfile]
52
50
  #
53
51
  def shot
54
- path = filepath
55
-
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'
52
+ Tempfile.open(['gnawrnip', '.png']) do |fp|
53
+ session.save_screenshot(fp.path)
54
+ fp
55
+ end
64
56
  end
65
57
  end
66
58
  end
@@ -1,4 +1,3 @@
1
- require 'base64'
2
1
  require 'turnip_formatter/step_template/exception'
3
2
  require 'gnawrnip/developer'
4
3
 
@@ -6,8 +5,8 @@ module Gnawrnip
6
5
  class StepScreenshot < TurnipFormatter::StepTemplate::Exception
7
6
  on_failed :build
8
7
 
9
- def self.scss
10
- File.read(File.dirname(__FILE__) + '/gnawrnip.scss')
8
+ def self.css
9
+ File.read(File.dirname(__FILE__) + '/gnawrnip.css')
11
10
  end
12
11
 
13
12
  def build(example)
@@ -46,15 +45,15 @@ module Gnawrnip
46
45
  EOS
47
46
  end
48
47
 
49
- def single_image(path)
48
+ def single_image(file)
50
49
  text = '<div class="screenshot">'
51
- text += develop([path])
50
+ text += develop([file])
52
51
  text + '</div>'
53
52
  end
54
53
 
55
- def develop(paths)
56
- paths.map do |path|
57
- image = developer.develop(path)
54
+ def develop(files)
55
+ files.map do |file|
56
+ image = developer.develop(file.path)
58
57
  image.to_html
59
58
  end.join
60
59
  end
@@ -1,3 +1,3 @@
1
1
  module Gnawrnip
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
data/lib/gnawrnip.rb CHANGED
@@ -4,8 +4,6 @@ require 'gnawrnip/rspec'
4
4
  require 'gnawrnip/photographer'
5
5
 
6
6
  module Gnawrnip
7
- SCREENSHOT_OUTPUT_DIR = File.expand_path('./gnawrnip_tmp')
8
-
9
7
  class << self
10
8
  #
11
9
  # [Boolean] Whether to make animation GIF
@@ -35,12 +33,6 @@ module Gnawrnip
35
33
  def ready!
36
34
  require 'gnawrnip/ext/capybara/session' if animation?
37
35
  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)
44
36
  end
45
37
 
46
38
  def animation?
@@ -58,6 +50,6 @@ module Gnawrnip
58
50
  end
59
51
 
60
52
  Gnawrnip.configure do |c|
61
- c.make_animation = true
62
- c.max_frame_size = nil
53
+ c.make_animation = true
54
+ c.max_frame_size = nil
63
55
  end
@@ -13,11 +13,7 @@ module Gnawrnip
13
13
 
14
14
  context 'image size is 640x480' do
15
15
  let(:canvas) do
16
- double(dimension: dimension, save: nil)
17
- end
18
-
19
- let(:dimension) do
20
- double(width: 640, height: 480)
16
+ double(width: 640, height: 480, save: nil)
21
17
  end
22
18
 
23
19
  describe '.width' do
@@ -33,14 +29,10 @@ module Gnawrnip
33
29
  describe '.resize' do
34
30
  let(:canvas) do
35
31
  canvas = super()
36
- expect(canvas).to receive(:resample_bilinear).with(320, 240).and_return(canvas)
32
+ expect(canvas).to receive(:resample_bilinear!).with(320, 240).once
37
33
  canvas
38
34
  end
39
35
 
40
- before do
41
- expect_any_instance_of(Image).to receive(:analysis).twice
42
- end
43
-
44
36
  it { image.resize(320, 240) }
45
37
  end
46
38
  end
@@ -18,7 +18,13 @@ module Gnawrnip
18
18
  subject { template.build(example) }
19
19
 
20
20
  context 'has multiple data' do
21
- let(:paths) { ['/path/to/A.png', '/path/to/B.png', '/path/to/C.png'] }
21
+ let(:paths) do
22
+ [
23
+ double(path: '/path/to/A.png'),
24
+ double(path: '/path/to/B.png'),
25
+ double(path: '/path/to/C.png')
26
+ ]
27
+ end
22
28
 
23
29
  it 'should get image tag and source that base64 encoded' do
24
30
  should include '<div class="screenshot animation">'
@@ -27,7 +33,7 @@ module Gnawrnip
27
33
  end
28
34
 
29
35
  context 'has single data' do
30
- let(:paths) { ['/path/to/A.png'] }
36
+ let(:paths) { [double(path: '/path/to/A.png')] }
31
37
  it do
32
38
  should include '<div class="screenshot">'
33
39
  should_not include '<div class="nav">'
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.3.0
4
+ version: 0.3.1
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-08-17 00:00:00.000000000 Z
11
+ date: 2014-09-30 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.3.0
33
+ version: 0.3.2
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.3.0
40
+ version: 0.3.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: oily_png
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -132,8 +132,8 @@ files:
132
132
  - lib/gnawrnip.rb
133
133
  - lib/gnawrnip/developer.rb
134
134
  - lib/gnawrnip/ext/capybara/session.rb
135
+ - lib/gnawrnip/gnawrnip.css
135
136
  - lib/gnawrnip/gnawrnip.js
136
- - lib/gnawrnip/gnawrnip.scss
137
137
  - lib/gnawrnip/image.rb
138
138
  - lib/gnawrnip/no_screenshot.png
139
139
  - lib/gnawrnip/photographer.rb
@@ -1,47 +0,0 @@
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
- }