heavens_door 0.1.0

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: 6e2b7e1472bb3a213d8a274264dec35b2d7ef99b3d07478a17ac0c2eea63ba4a
4
+ data.tar.gz: 52a1337ad38a19babbf1df3bee6f6ef0e477da2a5e57b54140d5b16387ea679a
5
+ SHA512:
6
+ metadata.gz: a3f54255544342a67332e7ab5a3a1c5285c6450b24d17439cf5ab16d503576b8e6e1b8fd2c7cb7e5686a7d6f0c4eb69e0ea9599a30823267e0747a3439731518
7
+ data.tar.gz: e43bb5fa41d150ebe6f82c154c687ae1381980c7b5cc7f0a5152a18f95a32927020dff36999e115fda72e82a01ec7e704179fa4b29da01e849195e998ba850bc
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in heavens_door.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Akira Matsuda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Heaven's Door
2
+
3
+ A tiny Rails engine that generates capybara test scenario by recording browser operation in development env.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your Rails application's Gemfile (in most cases, for development group only):
9
+
10
+ ```ruby
11
+ gem 'heavens_door'
12
+ ```
13
+
14
+
15
+ ## Usage
16
+
17
+ ![Usage](heavens_door.gif)
18
+
19
+
20
+ ### Start Recording
21
+ Visit your development with your browser, then click the ⏺ button on the top right.
22
+
23
+
24
+ ### Generate Schenarios
25
+ Just manipulate the browser, like fill-in the forms and submit, or click the links.
26
+ Your operations will be recorded on the browser.
27
+
28
+ ### Copy to Clipboard
29
+ You can export the operation as a Capybara test scenario script by clicking the 📋 button.
30
+
31
+ ### Stop Recording
32
+ To stop recording and clear the whole recorded scenario, click the ⏹ button.
33
+
34
+
35
+ ## Contributing
36
+
37
+ Pull requests are welcome on GitHub at https://github.com/amatsuda/heavens_door.
38
+
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,80 @@
1
+ (fn => {
2
+ if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
3
+ fn();
4
+ } else {
5
+ if (Turbolinks) {
6
+ document.addEventListener('turbolinks:load', fn);
7
+ } else {
8
+ document.addEventListener('DOMContentLoaded', fn);
9
+ }
10
+ }
11
+ })(() => {
12
+ document.getElementById('heavens-door-start').addEventListener('click', e => {
13
+ document.getElementById('heavens-door-start').style.display = 'none';
14
+ document.getElementById('heavens-door-stop').style.display = 'inline';
15
+ document.getElementById('heavens-door-copy').style.display = 'inline';
16
+
17
+ if (!sessionStorage.heavensDoor) {
18
+ sessionStorage.heavensDoor = ` scenario 'GENERATED' do
19
+ visit '${window.location.pathname}'\n\n`;
20
+ }
21
+ });
22
+
23
+ document.getElementById('heavens-door-stop').addEventListener('click', e => {
24
+ document.getElementById('heavens-door-start').style.display = 'inline';
25
+ document.getElementById('heavens-door-stop').style.display = 'none';
26
+ document.getElementById('heavens-door-copy').style.display = 'none';
27
+ sessionStorage.clear('heavensDoor');
28
+ });
29
+
30
+ document.getElementById('heavens-door-copy').addEventListener('click', e => {
31
+ navigator.clipboard.writeText(sessionStorage.heavensDoor)
32
+ .catch(err => {
33
+ console.error('Could not copy text: ', err);
34
+ alert(sessionStorage.heavensDoor);
35
+ });
36
+ });
37
+
38
+ if (sessionStorage.heavensDoor) {
39
+ document.getElementById('heavens-door-start').click();
40
+ }
41
+
42
+ function labelIdForElement(el) {
43
+ if (el.id) {
44
+ const label = document.querySelector(`label[for=${el.id}]`);
45
+ return label ? label.innerHTML : el.id;
46
+ }
47
+ }
48
+
49
+ Array.from(document.getElementsByTagName('form')).forEach(form => {
50
+ form.addEventListener('submit', e => {
51
+ if (sessionStorage.heavensDoor) {
52
+ Array.from(form.querySelectorAll('input,textarea')).forEach(el => {
53
+ let target = labelIdForElement(el) || el.id;
54
+
55
+ if ((el.type == 'text') || (el.type == 'textarea') || (el.type == 'search') || (el.type == 'number') || (el.type == 'email') || (el.type == 'url') || (el.type == 'password') || (el.type == 'tel') || (el.type == 'date')) {
56
+ if (el.value) {
57
+ sessionStorage.heavensDoor += ` fill_in '${target}', with: '${el.value}'\n`;
58
+ }
59
+ } else if (el.type == 'select') {
60
+ sessionStorage.heavensDoor += ` select '${el[el.selectedIndex].value}', from: '${target}'\n`;
61
+ } else if ((el.type == 'radio') && el.checked) {
62
+ sessionStorage.heavensDoor += ` choose '${el.value}'\n`;
63
+ } else if ((el.type == 'checkbox') && el.checked) {
64
+ sessionStorage.heavensDoor += ` check '${el.value}'\n`;
65
+ }
66
+ })
67
+
68
+ sessionStorage.heavensDoor += ` click_button '${form.querySelector('input[type=submit]').value}'\n\n`;
69
+ }
70
+ });
71
+ })
72
+
73
+ Array.from(document.getElementsByTagName('a')).forEach(a => {
74
+ a.addEventListener('click', e => {
75
+ if (sessionStorage.heavensDoor) {
76
+ sessionStorage.heavensDoor += ` click_link '${a.text}'\n\n`;
77
+ }
78
+ });
79
+ })
80
+ })
@@ -0,0 +1 @@
1
+ #heavens-door { position: absolute; top: 0; right: 0; font-size: 13px; cursor: pointer; } #heavens-door-stop,#heavens-door-copy { display: none; }
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "heavens_door"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "heavens_door/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "heavens_door"
8
+ spec.version = HeavensDoor::VERSION
9
+ spec.authors = ["Akira Matsuda"]
10
+ spec.email = ["ronnie@dio.jp"]
11
+
12
+ spec.summary = 'The Capybara scenario writer'
13
+ spec.description = 'A Rails engine that generates Capybara scenario in the browser'
14
+ spec.homepage = 'https://github.com/amatsuda/heavens_door'
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+ end
data/heavens_door.gif ADDED
Binary file
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "heavens_door/version"
4
+ require_relative 'heavens_door/engine'
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'middleware'
4
+
5
+ module HeavensDoor
6
+ class Engine < ::Rails::Engine #:nodoc:
7
+ initializer 'HeavensDoor' do |app|
8
+ app.middleware.use HeavensDoor::Middleware
9
+
10
+ app.config.assets.precompile += %w(heavens_door.js heavens_door.css)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HeavensDoor
4
+ class Middleware
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ status, headers, body = @app.call env
11
+
12
+ if headers && headers['Content-Type']&.include?('text/html') && (env['REQUEST_PATH'] !~ %r[^/*heavens_door/]) &&
13
+ (!env['action_dispatch.content_security_policy']&.script_src('unsafe-inline') && !env['action_dispatch.content_security_policy']&.style_src('unsafe-inline')) # the Rails default top page has this
14
+ case body
15
+ when ActionDispatch::Response, ActionDispatch::Response::RackBody
16
+ body = body.body
17
+ when Array
18
+ body = body[0]
19
+ end
20
+
21
+ body.sub!(/<\/head[^>]*>/) { %Q[<link rel="stylesheet" href="/assets/heavens_door.css" /><script src="/assets/heavens_door.js"></script>\n#{$~}] }
22
+ body.sub!(/<body[^>]*>/) { %Q[#{$~}\n<div id="heavens-door"><span id="heavens-door-start">⏺</span><span id="heavens-door-stop">⏹</span><span id="heavens-door-copy">📋</span></div>] }
23
+
24
+ [status, headers, [body]]
25
+ else
26
+ [status, headers, body]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module HeavensDoor
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heavens_door
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Akira Matsuda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: A Rails engine that generates Capybara scenario in the browser
56
+ email:
57
+ - ronnie@dio.jp
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - MIT-LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - app/assets/javascripts/heavens_door.js
69
+ - app/assets/stylesheets/heavens_door.css
70
+ - bin/console
71
+ - bin/setup
72
+ - heavens_door.gemspec
73
+ - heavens_door.gif
74
+ - lib/heavens_door.rb
75
+ - lib/heavens_door/engine.rb
76
+ - lib/heavens_door/middleware.rb
77
+ - lib/heavens_door/version.rb
78
+ homepage: https://github.com/amatsuda/heavens_door
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.0.1
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: The Capybara scenario writer
101
+ test_files: []