capybara-flow 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d2d4089bc504959b5d01fee1607480e0fa4e1977667b29381abba52516885589
4
+ data.tar.gz: e889449c864412652e57836cc8355e80e01700713949d4043661bc3d29af037a
5
+ SHA512:
6
+ metadata.gz: 3db3c1d8c1cc46b6edf34f1090a335a4b8e0c27e84e93ae1454a36c01f492dcd978cf3888b0a6d3e7f704749f28c460cfc7d1db67a744d8d22838ece194dd6a2
7
+ data.tar.gz: 962e010b739781f9a0f1e1c2dba4d8e462e53a963b138e72309476501a8ba2ea64f6844faf8ff3ece4bc49595b38a5cb8b2312ff878dae938668291ff678f99e
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ capybara-flow
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.5
data/.simplecov ADDED
@@ -0,0 +1,3 @@
1
+ SimpleCov.start do
2
+ add_filter "/spec/"
3
+ end
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capybara-flow.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Caleb Buxton
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ Capybara::Flow
2
+ =
3
+
4
+ Take a peak at your headless browser acceptance tests. Capybara::Flow captures screenshots after Capybara driven user actions in order to compose an animation of your scenario.
5
+
6
+ ## Installation
7
+
8
+ Capybara::Flow depends on ImageMagick. On newer versions of OS X installation is simple:
9
+ ```
10
+ brew unlink imagemagick #if you already have imagemagick installed
11
+ brew install imagemagick@6 && brew link imagemagick@6 --force
12
+ ```
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'capybara-flow', group: :test
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install capybara-flow
25
+
26
+ ## Usage
27
+
28
+ `Capybara::Flow` automatically hooks in to RSpec system tests with the tag `:js`.
29
+ It depends on a driver that implements ```#save_screenshot```
30
+
31
+ ## Configuration
32
+
33
+ Add the following to `spec/support/capybara_flow.rb`
34
+
35
+ ```ruby
36
+ require 'capybara/flow/hooks/rspec'
37
+
38
+ Capybara::Flow.configure do |config|
39
+ config.save_path = Rails.root.join("tmp/flow")
40
+ config.iterations = 1
41
+ config.delay_in_ms = 700
42
+ end
43
+
44
+ ```
45
+
46
+ ## Credit
47
+
48
+ This is forked from https://github.com/surzycki/capybara-animate
49
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = %w{--format progress}
6
+ end
7
+
8
+ task :default => [:spec]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "capybara-flow"
7
+ spec.version = File.read("VERSION")
8
+ spec.authors = ["Will Read"]
9
+ spec.email = ["will.read@gmail.com"]
10
+ spec.description = %q{Composes GIF animations from screenshots taken after capybara specified user actions.}
11
+ spec.summary = %q{Gif animations of your headless browser tests.}
12
+ spec.homepage = "https://github.com/TildeWill/capybara-flow"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(spec)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "capybara"
21
+ spec.add_dependency "rmagick"
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "simplecov"
27
+ end
@@ -0,0 +1,74 @@
1
+ require 'capybara/flow/empty_recorder'
2
+
3
+ module Capybara
4
+ module Flow
5
+ VERSION = File.read(File.join(File.dirname(__FILE__), "..", "..", "VERSION")).freeze
6
+
7
+ class << self
8
+ attr_writer :configuration
9
+ end
10
+
11
+ def self.configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
15
+ def self.configure
16
+ yield(configuration)
17
+ end
18
+
19
+ def self.included(base)
20
+ base.send(:prepend, UserActions)
21
+ end
22
+
23
+ def recorder
24
+ @recorder ||= EmptyRecorder.new
25
+ end
26
+
27
+ def recorder=(other)
28
+ @recorder = other
29
+ end
30
+
31
+ MATCHERS = [
32
+ :have_content
33
+ ]
34
+
35
+ USER_ACTIONS = [
36
+ :attach_file,
37
+ :check,
38
+ :uncheck,
39
+ :choose,
40
+ :click_button,
41
+ :click_link,
42
+ :click_link_or_button,
43
+ :click_on,
44
+ :evaluate_script,
45
+ :execute_script,
46
+ :fill_in,
47
+ :go_back,
48
+ :go_forward,
49
+ :select,
50
+ :unselect,
51
+ :visit
52
+ ].freeze
53
+
54
+ module UserActions
55
+ USER_ACTIONS.each do |action_method|
56
+ define_method action_method do |*args, &block|
57
+ super(*args, &block)
58
+ self.recorder.add(self)
59
+ end
60
+ end
61
+
62
+ MATCHERS.each do |matcher_method|
63
+ define_method matcher_method do |arg|
64
+ self.recorder.add(self)
65
+ super(arg)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ require 'capybara/flow/gif_animator'
73
+ require 'capybara/flow/gif_recorder'
74
+ require 'capybara/flow/configuration'
@@ -0,0 +1,15 @@
1
+ module Capybara
2
+ module Flow
3
+ class Configuration
4
+ attr_accessor :delay_in_ms
5
+ attr_accessor :iterations
6
+ attr_accessor :save_path
7
+
8
+ def initialize
9
+ @delay_in_ms = 70
10
+ @iterations = nil
11
+ @save_path = "html-report/"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Capybara
2
+ module Flow
3
+ class EmptyRecorder
4
+
5
+ def add(_page)
6
+
7
+ end
8
+
9
+ def generate!
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ require "RMagick"
2
+
3
+ module Capybara
4
+ module Flow
5
+ class GifAnimator
6
+ attr_reader :frames, :delay, :iterations, :output_file
7
+
8
+ def initialize(output_file, options = {})
9
+ @delay = options[:delay_in_ms]
10
+ @iterations = options[:iterations]
11
+ @output_file = output_file
12
+ @frames = []
13
+ end
14
+
15
+ def add(frame)
16
+ frames << frame
17
+ end
18
+
19
+ def generate!
20
+ gif = ::Magick::ImageList.new(*frames)
21
+ gif.delay = delay if delay
22
+ gif.iterations = iterations if iterations
23
+ gif.ticks_per_second = 1000
24
+ gif.write(output_file)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ module Capybara
2
+ module Flow
3
+ class GifRecorder
4
+ attr_reader :output_file
5
+
6
+ def initialize(output_name)
7
+ @frame_dir = output_name
8
+ @output_file = "#{output_name}.gif"
9
+ make_path_unless_exists(output_file)
10
+ make_path_unless_exists(@frame_dir)
11
+ @gif_animator = GifAnimator.new(output_file, delay_in_ms: Capybara::Flow.configuration.delay_in_ms, iterations: Capybara::Flow.configuration.iterations)
12
+ @tmpdir = Dir.mktmpdir
13
+ end
14
+
15
+ def add(page)
16
+ file = File.join(@frame_dir, "#{current_frame}.png")
17
+ page.save_screenshot(file, width: 320, height: 480)
18
+ gif_animator.add(file)
19
+ end
20
+
21
+ def generate!
22
+ gif_animator.generate!
23
+ end
24
+
25
+ private
26
+ attr_reader :tmpdir, :gif_animator
27
+
28
+ def current_frame
29
+ gif_animator.frames.length
30
+ end
31
+
32
+ def make_path_unless_exists(file)
33
+ FileUtils.mkdir_p(File.dirname(file)) unless File.exists?(File.dirname(file))
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ if defined?(Capybara::Session)
2
+ Capybara::Session.send(:include, Capybara::Flow)
3
+ RSpec.configure do |config|
4
+ config.before(:each, :js) do |example|
5
+ output_path = File.join(Capybara::Flow.configuration.save_path, example.full_description.parameterize)
6
+ page.recorder = Capybara::Flow::GifRecorder.new(output_path)
7
+ end
8
+
9
+ config.after(:each, :js) do
10
+ page.recorder.add(page)
11
+ page.recorder.generate!
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ require 'capybara/flow/empty_recorder'
4
+
5
+ describe Capybara::Flow::EmptyRecorder, type: :recorder do
6
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'securerandom'
3
+
4
+ require 'capybara/flow/gif_recorder'
5
+
6
+ describe Capybara::Flow::GifRecorder, type: :recorder do
7
+ let(:gif_animator) { instance_double(Capybara::Flow::GifAnimator, add: true, frames: [], generate!: true) }
8
+ let(:tmpdir) { FileUtils.mkdir_p(Dir.pwd+"/tmp").first }
9
+ let(:output_name) { "the file name" }
10
+ let(:recorder) { described_class.new(output_name) }
11
+
12
+ before do
13
+ allow(Capybara::Flow::GifAnimator).to receive(:new).and_return(gif_animator)
14
+ allow(Dir).to receive(:mktmpdir).and_return(tmpdir)
15
+ end
16
+
17
+ subject { recorder }
18
+
19
+ it "should create the output path if it does not yet exist" do
20
+ unique_path = Dir.pwd+"/tmp/#{SecureRandom::uuid}/foobar"
21
+ expect do
22
+ described_class.new(unique_path)
23
+ end.to change { File.exists?(File.dirname(unique_path))}
24
+ end
25
+
26
+ it "sets the output_file based on initialization values" do
27
+ expect(subject.output_file).to eql("#{output_name}.gif")
28
+ end
29
+
30
+ describe "#add" do
31
+ let(:page) { double(save_screenshot: true) }
32
+
33
+ let(:adding) { proc { recorder.add(page) } }
34
+ subject { adding.call }
35
+
36
+ it "should save a screenshot from the page to a file in the output directory so you can go frame by frame" do
37
+ expect(page).to receive(:save_screenshot).with("the file name/0.png", hash_including(:width, :height))
38
+ subject
39
+ end
40
+
41
+ it "should add the saved frame to the animation" do
42
+ expect(gif_animator).to receive(:add).with("the file name/0.png")
43
+ subject
44
+ end
45
+ end
46
+
47
+ describe "#generate!" do
48
+ let(:generating) { proc { recorder.generate! } }
49
+ subject { generating.call }
50
+
51
+ it "should generate the animation" do
52
+ expect(gif_animator).to receive(:generate!)
53
+ subject
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capybara::Flow do
4
+ ExpectedUserActions = [
5
+ :attach_file,
6
+ :check,
7
+ :choose,
8
+ :click_button,
9
+ :click_link,
10
+ :click_link_or_button,
11
+ :click_on,
12
+ :evaluate_script,
13
+ :execute_script,
14
+ :fill_in,
15
+ :go_back,
16
+ :go_forward,
17
+ :unselect,
18
+ :visit,
19
+ ]
20
+ class Dummy
21
+ ExpectedUserActions.each do |lazy|
22
+ define_method lazy do |*args, &block|
23
+ instance_variable_set("@#{lazy}", true)
24
+ end
25
+
26
+ define_method "#{lazy}?" do |*args, &block|
27
+ !!instance_variable_get("@#{lazy}")
28
+ end
29
+ end
30
+ end
31
+
32
+ it 'should have a version number' do
33
+ expect(Capybara::Flow::VERSION).to_not be_nil
34
+ end
35
+
36
+ context "included into a class" do
37
+ let(:described_class) { Dummy.send(:include, Capybara::Flow) }
38
+
39
+ context "the instance" do
40
+ subject { described_class.new }
41
+
42
+ it "should have an EmptyRecorder set to recorder" do
43
+ expect(subject.recorder).to be_a(Capybara::Flow::EmptyRecorder)
44
+ end
45
+
46
+ it "should be able to set a recorder" do
47
+ expect do
48
+ subject.recorder = :foo
49
+ end.to change { subject.recorder }
50
+ end
51
+
52
+ context "should add itself to the recorder" do
53
+ ExpectedUserActions.each do |attribute|
54
+ it "for #{attribute}" do
55
+ expect(subject.recorder).to receive(:add).with(subject)
56
+ subject.send(attribute)
57
+ end
58
+
59
+ it "and still call the original #{attribute}" do
60
+ expect do
61
+ subject.send(attribute)
62
+ end.to change { subject.send"#{attribute}?" }
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'pry'
4
+ require 'simplecov'
5
+
6
+ require 'capybara/flow'
7
+
8
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| puts f; require f }
@@ -0,0 +1,13 @@
1
+ shared_examples_for type: :recorder do
2
+ it { should respond_to(:add) }
3
+
4
+ it { should respond_to(:generate!) }
5
+
6
+ describe "#add" do
7
+ it "should accept an argument" do
8
+ expect do
9
+ subject.add(double(save_screenshot: true))
10
+ end.to_not raise_error
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-flow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Will Read
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rmagick
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Composes GIF animations from screenshots taken after capybara specified
112
+ user actions.
113
+ email:
114
+ - will.read@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".ruby-gemset"
122
+ - ".ruby-version"
123
+ - ".simplecov"
124
+ - ".travis.yml"
125
+ - Gemfile
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - VERSION
130
+ - capybara-flow.gemspec
131
+ - lib/capybara/flow.rb
132
+ - lib/capybara/flow/configuration.rb
133
+ - lib/capybara/flow/empty_recorder.rb
134
+ - lib/capybara/flow/gif_animator.rb
135
+ - lib/capybara/flow/gif_recorder.rb
136
+ - lib/capybara/flow/hooks/rspec.rb
137
+ - spec/capybara/flow/empty_recorder_spec.rb
138
+ - spec/capybara/flow/gif_recorder_spec.rb
139
+ - spec/capybara/flow_spec.rb
140
+ - spec/spec_helper.rb
141
+ - spec/support/shared_examples/a_recorder.rb
142
+ homepage: https://github.com/TildeWill/capybara-flow
143
+ licenses:
144
+ - MIT
145
+ metadata: {}
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubygems_version: 3.0.6
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: Gif animations of your headless browser tests.
165
+ test_files:
166
+ - spec/capybara/flow/empty_recorder_spec.rb
167
+ - spec/capybara/flow/gif_recorder_spec.rb
168
+ - spec/capybara/flow_spec.rb
169
+ - spec/spec_helper.rb
170
+ - spec/support/shared_examples/a_recorder.rb