magic_test 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +133 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +172 -0
- data/LICENSE.txt +21 -0
- data/README.md +95 -0
- data/Rakefile +10 -0
- data/app/views/magic_test/_context_menu.html +41 -0
- data/app/views/magic_test/_finders.html +51 -0
- data/app/views/magic_test/_javascript_helpers.html +132 -0
- data/app/views/magic_test/_key_codes.html +50 -0
- data/app/views/magic_test/_listeners.html +9 -0
- data/app/views/magic_test/_mutation_observer.html +36 -0
- data/app/views/magic_test/_storage.html +9 -0
- data/app/views/magic_test/_support.html.erb +13 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/generators/magic_test/install_generator.rb +40 -0
- data/lib/generators/magic_test/templates/config/initializers/magic_test.rb +3 -0
- data/lib/magic_test.rb +15 -0
- data/lib/magic_test/engine.rb +17 -0
- data/lib/magic_test/railtie.rb +7 -0
- data/lib/magic_test/support.rb +97 -0
- data/lib/magic_test/version.rb +3 -0
- data/lib/tasks/magic_test.rake +6 -0
- data/magic_test.gemspec +32 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dd7c21ea35cc7ae4dee04062fbe0dde585a74606ed6f930b57b3f60a533a35ae
|
4
|
+
data.tar.gz: 5a1e4c3b4f0c7d2d172c3837e6fcabd3820d80a0ff96e4cd0cd08146e38626e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf114c2b6804a3d815b3f4527c8402738a16431768b8d88491ebb2446a9302743bd30779494f8d87c2fd62e60b46628ac334446c0779761bc34f284387cac0e3
|
7
|
+
data.tar.gz: 6228f530035cc236b34b226e36eeca8092fef7ff545c2952d5740a430689c776c6ffdc9266fc6b911cd35151ece8d1fb4f4f8d6b79e480e153d3309c089f3e2d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
|
2
|
+
# Contributor Covenant Code of Conduct
|
3
|
+
|
4
|
+
## Our Pledge
|
5
|
+
|
6
|
+
We as members, contributors, and leaders pledge to make participation in our
|
7
|
+
community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
9
|
+
identity and expression, level of experience, education, socio-economic status,
|
10
|
+
nationality, personal appearance, race, caste, color, religion, or sexual identity
|
11
|
+
and orientation.
|
12
|
+
|
13
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
14
|
+
diverse, inclusive, and healthy community.
|
15
|
+
|
16
|
+
## Our Standards
|
17
|
+
|
18
|
+
Examples of behavior that contributes to a positive environment for our
|
19
|
+
community include:
|
20
|
+
|
21
|
+
* Demonstrating empathy and kindness toward other people
|
22
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
23
|
+
* Giving and gracefully accepting constructive feedback
|
24
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
25
|
+
and learning from the experience
|
26
|
+
* Focusing on what is best not just for us as individuals, but for the
|
27
|
+
overall community
|
28
|
+
|
29
|
+
Examples of unacceptable behavior include:
|
30
|
+
|
31
|
+
* The use of sexualized language or imagery, and sexual attention or
|
32
|
+
advances of any kind
|
33
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
34
|
+
* Public or private harassment
|
35
|
+
* Publishing others' private information, such as a physical or email
|
36
|
+
address, without their explicit permission
|
37
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
38
|
+
professional setting
|
39
|
+
|
40
|
+
## Enforcement Responsibilities
|
41
|
+
|
42
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
43
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
44
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
45
|
+
or harmful.
|
46
|
+
|
47
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
48
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
49
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
50
|
+
decisions when appropriate.
|
51
|
+
|
52
|
+
## Scope
|
53
|
+
|
54
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
55
|
+
an individual is officially representing the community in public spaces.
|
56
|
+
Examples of representing our community include using an official e-mail address,
|
57
|
+
posting via an official social media account, or acting as an appointed
|
58
|
+
representative at an online or offline event.
|
59
|
+
|
60
|
+
## Enforcement
|
61
|
+
|
62
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
63
|
+
reported to the community leaders responsible for enforcement at
|
64
|
+
andrew@bullettrain.co.
|
65
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
66
|
+
|
67
|
+
All community leaders are obligated to respect the privacy and security of the
|
68
|
+
reporter of any incident.
|
69
|
+
|
70
|
+
## Enforcement Guidelines
|
71
|
+
|
72
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
73
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
74
|
+
|
75
|
+
### 1. Correction
|
76
|
+
|
77
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
78
|
+
unprofessional or unwelcome in the community.
|
79
|
+
|
80
|
+
**Consequence**: A private, written warning from community leaders, providing
|
81
|
+
clarity around the nature of the violation and an explanation of why the
|
82
|
+
behavior was inappropriate. A public apology may be requested.
|
83
|
+
|
84
|
+
### 2. Warning
|
85
|
+
|
86
|
+
**Community Impact**: A violation through a single incident or series
|
87
|
+
of actions.
|
88
|
+
|
89
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
90
|
+
interaction with the people involved, including unsolicited interaction with
|
91
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
92
|
+
includes avoiding interactions in community spaces as well as external channels
|
93
|
+
like social media. Violating these terms may lead to a temporary or
|
94
|
+
permanent ban.
|
95
|
+
|
96
|
+
### 3. Temporary Ban
|
97
|
+
|
98
|
+
**Community Impact**: A serious violation of community standards, including
|
99
|
+
sustained inappropriate behavior.
|
100
|
+
|
101
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
102
|
+
communication with the community for a specified period of time. No public or
|
103
|
+
private interaction with the people involved, including unsolicited interaction
|
104
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
105
|
+
Violating these terms may lead to a permanent ban.
|
106
|
+
|
107
|
+
### 4. Permanent Ban
|
108
|
+
|
109
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
110
|
+
standards, including sustained inappropriate behavior, harassment of an
|
111
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
112
|
+
|
113
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
114
|
+
the community.
|
115
|
+
|
116
|
+
## Attribution
|
117
|
+
|
118
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
119
|
+
version 2.0, available at
|
120
|
+
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
|
121
|
+
|
122
|
+
Community Impact Guidelines were inspired by
|
123
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
124
|
+
|
125
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
126
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
|
127
|
+
at [https://www.contributor-covenant.org/translations][translations].
|
128
|
+
|
129
|
+
[homepage]: https://www.contributor-covenant.org
|
130
|
+
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
|
131
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
132
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
133
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
magic_test (0.1.0)
|
5
|
+
capybara (~> 3.0)
|
6
|
+
pry
|
7
|
+
rails (~> 6.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actioncable (6.1.3)
|
13
|
+
actionpack (= 6.1.3)
|
14
|
+
activesupport (= 6.1.3)
|
15
|
+
nio4r (~> 2.0)
|
16
|
+
websocket-driver (>= 0.6.1)
|
17
|
+
actionmailbox (6.1.3)
|
18
|
+
actionpack (= 6.1.3)
|
19
|
+
activejob (= 6.1.3)
|
20
|
+
activerecord (= 6.1.3)
|
21
|
+
activestorage (= 6.1.3)
|
22
|
+
activesupport (= 6.1.3)
|
23
|
+
mail (>= 2.7.1)
|
24
|
+
actionmailer (6.1.3)
|
25
|
+
actionpack (= 6.1.3)
|
26
|
+
actionview (= 6.1.3)
|
27
|
+
activejob (= 6.1.3)
|
28
|
+
activesupport (= 6.1.3)
|
29
|
+
mail (~> 2.5, >= 2.5.4)
|
30
|
+
rails-dom-testing (~> 2.0)
|
31
|
+
actionpack (6.1.3)
|
32
|
+
actionview (= 6.1.3)
|
33
|
+
activesupport (= 6.1.3)
|
34
|
+
rack (~> 2.0, >= 2.0.9)
|
35
|
+
rack-test (>= 0.6.3)
|
36
|
+
rails-dom-testing (~> 2.0)
|
37
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
38
|
+
actiontext (6.1.3)
|
39
|
+
actionpack (= 6.1.3)
|
40
|
+
activerecord (= 6.1.3)
|
41
|
+
activestorage (= 6.1.3)
|
42
|
+
activesupport (= 6.1.3)
|
43
|
+
nokogiri (>= 1.8.5)
|
44
|
+
actionview (6.1.3)
|
45
|
+
activesupport (= 6.1.3)
|
46
|
+
builder (~> 3.1)
|
47
|
+
erubi (~> 1.4)
|
48
|
+
rails-dom-testing (~> 2.0)
|
49
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
50
|
+
activejob (6.1.3)
|
51
|
+
activesupport (= 6.1.3)
|
52
|
+
globalid (>= 0.3.6)
|
53
|
+
activemodel (6.1.3)
|
54
|
+
activesupport (= 6.1.3)
|
55
|
+
activerecord (6.1.3)
|
56
|
+
activemodel (= 6.1.3)
|
57
|
+
activesupport (= 6.1.3)
|
58
|
+
activestorage (6.1.3)
|
59
|
+
actionpack (= 6.1.3)
|
60
|
+
activejob (= 6.1.3)
|
61
|
+
activerecord (= 6.1.3)
|
62
|
+
activesupport (= 6.1.3)
|
63
|
+
marcel (~> 0.3.1)
|
64
|
+
mimemagic (~> 0.3.2)
|
65
|
+
activesupport (6.1.3)
|
66
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
67
|
+
i18n (>= 1.6, < 2)
|
68
|
+
minitest (>= 5.1)
|
69
|
+
tzinfo (~> 2.0)
|
70
|
+
zeitwerk (~> 2.3)
|
71
|
+
addressable (2.7.0)
|
72
|
+
public_suffix (>= 2.0.2, < 5.0)
|
73
|
+
builder (3.2.4)
|
74
|
+
capybara (3.35.3)
|
75
|
+
addressable
|
76
|
+
mini_mime (>= 0.1.3)
|
77
|
+
nokogiri (~> 1.8)
|
78
|
+
rack (>= 1.6.0)
|
79
|
+
rack-test (>= 0.6.3)
|
80
|
+
regexp_parser (>= 1.5, < 3.0)
|
81
|
+
xpath (~> 3.2)
|
82
|
+
coderay (1.1.3)
|
83
|
+
concurrent-ruby (1.1.8)
|
84
|
+
crass (1.0.6)
|
85
|
+
erubi (1.10.0)
|
86
|
+
globalid (0.4.2)
|
87
|
+
activesupport (>= 4.2.0)
|
88
|
+
i18n (1.8.9)
|
89
|
+
concurrent-ruby (~> 1.0)
|
90
|
+
loofah (2.9.0)
|
91
|
+
crass (~> 1.0.2)
|
92
|
+
nokogiri (>= 1.5.9)
|
93
|
+
mail (2.7.1)
|
94
|
+
mini_mime (>= 0.1.1)
|
95
|
+
marcel (0.3.3)
|
96
|
+
mimemagic (~> 0.3.2)
|
97
|
+
method_source (1.0.0)
|
98
|
+
mimemagic (0.3.5)
|
99
|
+
mini_mime (1.0.2)
|
100
|
+
mini_portile2 (2.5.0)
|
101
|
+
minitest (5.14.4)
|
102
|
+
nio4r (2.5.5)
|
103
|
+
nokogiri (1.11.1)
|
104
|
+
mini_portile2 (~> 2.5.0)
|
105
|
+
racc (~> 1.4)
|
106
|
+
nokogiri (1.11.1-x86_64-darwin)
|
107
|
+
racc (~> 1.4)
|
108
|
+
pry (0.14.0)
|
109
|
+
coderay (~> 1.1)
|
110
|
+
method_source (~> 1.0)
|
111
|
+
public_suffix (4.0.6)
|
112
|
+
racc (1.5.2)
|
113
|
+
rack (2.2.3)
|
114
|
+
rack-test (1.1.0)
|
115
|
+
rack (>= 1.0, < 3)
|
116
|
+
rails (6.1.3)
|
117
|
+
actioncable (= 6.1.3)
|
118
|
+
actionmailbox (= 6.1.3)
|
119
|
+
actionmailer (= 6.1.3)
|
120
|
+
actionpack (= 6.1.3)
|
121
|
+
actiontext (= 6.1.3)
|
122
|
+
actionview (= 6.1.3)
|
123
|
+
activejob (= 6.1.3)
|
124
|
+
activemodel (= 6.1.3)
|
125
|
+
activerecord (= 6.1.3)
|
126
|
+
activestorage (= 6.1.3)
|
127
|
+
activesupport (= 6.1.3)
|
128
|
+
bundler (>= 1.15.0)
|
129
|
+
railties (= 6.1.3)
|
130
|
+
sprockets-rails (>= 2.0.0)
|
131
|
+
rails-dom-testing (2.0.3)
|
132
|
+
activesupport (>= 4.2.0)
|
133
|
+
nokogiri (>= 1.6)
|
134
|
+
rails-html-sanitizer (1.3.0)
|
135
|
+
loofah (~> 2.3)
|
136
|
+
railties (6.1.3)
|
137
|
+
actionpack (= 6.1.3)
|
138
|
+
activesupport (= 6.1.3)
|
139
|
+
method_source
|
140
|
+
rake (>= 0.8.7)
|
141
|
+
thor (~> 1.0)
|
142
|
+
rake (13.0.3)
|
143
|
+
regexp_parser (2.1.1)
|
144
|
+
sprockets (4.0.2)
|
145
|
+
concurrent-ruby (~> 1.0)
|
146
|
+
rack (> 1, < 3)
|
147
|
+
sprockets-rails (3.2.2)
|
148
|
+
actionpack (>= 4.0)
|
149
|
+
activesupport (>= 4.0)
|
150
|
+
sprockets (>= 3.0.0)
|
151
|
+
thor (1.1.0)
|
152
|
+
tzinfo (2.0.4)
|
153
|
+
concurrent-ruby (~> 1.0)
|
154
|
+
websocket-driver (0.7.3)
|
155
|
+
websocket-extensions (>= 0.1.0)
|
156
|
+
websocket-extensions (0.1.5)
|
157
|
+
xpath (3.2.0)
|
158
|
+
nokogiri (~> 1.8)
|
159
|
+
zeitwerk (2.4.2)
|
160
|
+
|
161
|
+
PLATFORMS
|
162
|
+
ruby
|
163
|
+
x86_64-darwin-20
|
164
|
+
|
165
|
+
DEPENDENCIES
|
166
|
+
bundler (~> 2.0)
|
167
|
+
magic_test!
|
168
|
+
minitest (~> 5.0)
|
169
|
+
rake (~> 13.0)
|
170
|
+
|
171
|
+
BUNDLED WITH
|
172
|
+
2.2.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Andrew Culver
|
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,95 @@
|
|
1
|
+
# Magic Test
|
2
|
+
|
3
|
+
Magic Test allows you to write Rails system tests interactively through a combination of trial-and-error in a debugger session and also just simple clicking around in the application being tested, all without the slowness of constantly restarting the testing environment.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Magic Test currently requires your application to have jQuery enabled.
|
8
|
+
|
9
|
+
Add this line to your application’s `Gemfile`:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'magic_test', group: :test
|
13
|
+
```
|
14
|
+
|
15
|
+
Then run the following in your shell:
|
16
|
+
|
17
|
+
```
|
18
|
+
bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
Next, run the install generator. If your application already includes jQuery, you can just run:
|
22
|
+
|
23
|
+
```
|
24
|
+
rails g magic_test:install
|
25
|
+
```
|
26
|
+
|
27
|
+
(If your application doesn't include jQuery, you'll need to let Magic Test know to include it as needed. Just add `no` to the end of the line above or adjust your configuration afterward in `config/initializers/magic_test.rb`. We'll only inject jQuery when Magic Test is actively running. It will never show up on CI.)
|
28
|
+
|
29
|
+
With this we will:
|
30
|
+
|
31
|
+
- Create a sample system test at `test/system/basics_test.rb` that invokes Magic Test.
|
32
|
+
- If your application was previously configured to run system tests with `:headless_chrome` or `:headless_firefox`, we will attempt to update your configuration so you can see the browser when you run tests with `MAGIC_TEST=1` as an environment variable.
|
33
|
+
|
34
|
+
Finally, because it’s hard for us to do automatically, you will need to add the following before any closing `</head>` tags in any of the files in `app/views/layouts`:
|
35
|
+
|
36
|
+
```
|
37
|
+
<%= render 'magic_test/support' if Rails.env.test? %>
|
38
|
+
```
|
39
|
+
|
40
|
+
You should be done now! To review what we’ve done for you, be sure to do a `git diff` at this point and make sure our generators didn’t break anything!
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
### Running the Example Test
|
45
|
+
|
46
|
+
1. Open `test/system/basics_test.rb` in your editor of choice.
|
47
|
+
2. Run `MAGIC_TEST=1 rails test:system test/system/basics_test.rb` on the shell.
|
48
|
+
|
49
|
+
This results in three windows:
|
50
|
+
|
51
|
+
1. **A debugger** where you can interactively write Capybara test code in the same context it would normally run.
|
52
|
+
2. **A browser** where you can click around the application and have your actions automatically converted into Capybara code.
|
53
|
+
3. **A editor** where you mostly just watch test code appear magically, but you can also edit it by hand should you need to.
|
54
|
+
|
55
|
+
If you have the screen real estate, we recommend organizing the three windows so you can see them all at the same time. This is the intended Magic Test developer experience.
|
56
|
+
|
57
|
+
### Using Magic Test in New or Existing Tests
|
58
|
+
|
59
|
+
Just add a call to `magic_test` anywhere you want to start interactively developing test behavior and run the test the same way we've described above.
|
60
|
+
|
61
|
+
### Writing Tests Manually in the Debugger Console
|
62
|
+
|
63
|
+
You’re now free to type Capybara commands in the debugger and see their results in the Chrome browser. If you type something and you’re with the result, type `ok` and hit enter to have the last line of code you wrote added to the test.
|
64
|
+
|
65
|
+
When you’re done writing the test interactively, you can press <kbd>Control</kbd> + <kbd>D</kbd> to finish running the test.
|
66
|
+
|
67
|
+
You can re-run `MAGIC_TEST=1 rails test:system test/system/basics_test.rb` to have the test execute up until the point where you stopped, and then re-enter the debugging session to continue writing the test. This is a great workflow for testing your work as you go.
|
68
|
+
|
69
|
+
When you’re actually done writing the test, be sure to remove the `magic_test` reference in the test file.
|
70
|
+
|
71
|
+
### Recording Your Test Actions in the Browser
|
72
|
+
|
73
|
+
You can also write your tests by simply using your app in the browser window. This isn’t perfect yet by any means, but you’ll definitely get a sense for where we’re going with this and it’s already a pretty magical experience and a major productivity booster.
|
74
|
+
|
75
|
+
You can click on buttons, click on links, fill in forms, and do many other things the way you would as a normal user. You may find there are certain shortcomings here, but our goal is to tackle all of those edge cases over time.
|
76
|
+
|
77
|
+
### Generating Assertions in the Browser
|
78
|
+
|
79
|
+
If you want to add an assertion that some content exists on the page, simply highlight some text and press <kbd>Control</kbd><kbd>Shift</kbd> + <kbd>A</kbd>. You should see an alert dialog confirming the assertion has been generated.
|
80
|
+
|
81
|
+
### Flushing In Browser Actions and Assertions to the Test File
|
82
|
+
|
83
|
+
The interactive actions you make in your app are not automatically written to your test. When you are ready to write your actions out to the test, go to the terminal window and type `flush`. This will flush all your recent actions out to the test file. It’s still early days for Magic Test, so you may find you need to clean up some of the output. Please don’t hesitate to submit new issues highlighting these scenarios so we can try to improve the results.
|
84
|
+
|
85
|
+
### Ambiguous Labels and Elements
|
86
|
+
|
87
|
+
When generating test code, we check to ensure a given label or element identifier won’t result in multiple or ambiguous matches the next time a test runs. If that situation arises, we’ll try to generate the appropriate `within` blocks and selectors to ensure the target button or field is disambiguated.
|
88
|
+
|
89
|
+
## Contributing
|
90
|
+
|
91
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bullet-train-co/magic_test. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
92
|
+
|
93
|
+
## License
|
94
|
+
|
95
|
+
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,41 @@
|
|
1
|
+
<script>
|
2
|
+
|
3
|
+
// TODO do we have to do this differently for turbo?
|
4
|
+
$(document).ready(function() {
|
5
|
+
enableKeyboardShortcuts();
|
6
|
+
});
|
7
|
+
|
8
|
+
function enableKeyboardShortcuts() {
|
9
|
+
function keydown(event) {
|
10
|
+
if (event.ctrlKey && event.shiftKey && event.key === 'A') {
|
11
|
+
event.preventDefault();
|
12
|
+
generateAssertion();
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
document.addEventListener('keydown', keydown, false);
|
17
|
+
|
18
|
+
function generateAssertion() {
|
19
|
+
var text = selectedText();
|
20
|
+
if (text.trim().length > 0) {
|
21
|
+
var action = "assert page.has_content?('" + text.replace("'", "\\\'") + "')";
|
22
|
+
var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
|
23
|
+
var target = "";
|
24
|
+
var options = "";
|
25
|
+
testingOutput.push({action: action, target: target, options: options});
|
26
|
+
sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));
|
27
|
+
alert("Generated an assertion for \"" + selectedText() + "\". Type `flush` in the debugger console to add it to your test file.");
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
function selectedText() {
|
32
|
+
var text = "";
|
33
|
+
if (window.getSelection) {
|
34
|
+
text = window.getSelection().toString();
|
35
|
+
} else if (document.selection && document.selection.type != "Control") {
|
36
|
+
text = document.selection.createRange().text;
|
37
|
+
}
|
38
|
+
return text;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
</script>
|
@@ -0,0 +1,51 @@
|
|
1
|
+
<script>
|
2
|
+
|
3
|
+
function getPathTo(element) {
|
4
|
+
if (element.tagName == 'HTML') {
|
5
|
+
return '/HTML[1]';
|
6
|
+
}
|
7
|
+
if (element===document.body) {
|
8
|
+
return '/HTML[1]/BODY[1]';
|
9
|
+
}
|
10
|
+
var ix = 0;
|
11
|
+
var siblings = element.parentNode.childNodes;
|
12
|
+
for (var i= 0; i<siblings.length; i++) {
|
13
|
+
var sibling= siblings[i];
|
14
|
+
if (sibling===element) {
|
15
|
+
return getPathTo(element.parentNode)+'/'+element.tagName+'['+(ix+1)+']';
|
16
|
+
}
|
17
|
+
if (sibling.nodeType===1 && sibling.tagName===element.tagName) {
|
18
|
+
ix++;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
// Chrome doesn't respond to the jQuery :visible selector properly so we have to do this:
|
24
|
+
function visibleFilter(){
|
25
|
+
return $(this).css('display') != 'none' && $(this).css('visibility') != 'hidden';
|
26
|
+
}
|
27
|
+
|
28
|
+
|
29
|
+
function finderForElement(element) {
|
30
|
+
// Try to find just using the element tagName
|
31
|
+
var tagName = element.tagName.toLowerCase();
|
32
|
+
if ($(tagName).length == 1) {
|
33
|
+
return `find('${tagName}')`;
|
34
|
+
}
|
35
|
+
// Try adding in the classes of the element
|
36
|
+
var classList = [].slice.apply(element.classList)
|
37
|
+
var classString = classList.length ? "." + classList.join('.') : "";
|
38
|
+
if (classList.length && $(tagName + classList).length == 1) {
|
39
|
+
return `find('${tagName}${classString}')`;
|
40
|
+
}
|
41
|
+
// Try adding in the text of the element
|
42
|
+
var text = element.textContent.trim();
|
43
|
+
if (text && $(tagName + classString + `:contains(${text}):visible`).filter(visibleFilter).length == 1) {
|
44
|
+
return `find('${tagName}${classString}', text: '${text}')`;
|
45
|
+
}
|
46
|
+
// use the xpath to the element
|
47
|
+
return `find(:xpath, '${getPathTo(element)}')`;
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
</script>
|
@@ -0,0 +1,132 @@
|
|
1
|
+
<script text="text/javascript">
|
2
|
+
|
3
|
+
$(function() {
|
4
|
+
console.log("🪄 Magic Test activated in the browser!")
|
5
|
+
initializeStorage();
|
6
|
+
initializeMutationObserver();
|
7
|
+
});
|
8
|
+
|
9
|
+
function clickFunction(event) {
|
10
|
+
var tagName = event.currentTarget.tagName
|
11
|
+
var action = ""
|
12
|
+
var target = ""
|
13
|
+
var options = ""
|
14
|
+
if (tagName == "BUTTON" || tagName == "A" || (tagName == "INPUT" && event.currentTarget.type == 'submit')) {
|
15
|
+
action = "click_on"
|
16
|
+
var target = event.currentTarget.value || event.currentTarget.text
|
17
|
+
if (!target) {
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
target = "\'" + target.trim().replace("'", "\\\'") + "\'"
|
21
|
+
} else if (tagName == "INPUT") {
|
22
|
+
let ignoreType = ['text', 'password', 'date', 'email', 'month', 'number', 'search']
|
23
|
+
if (ignoreType.includes(event.currentTarget.type)) {
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
var path = getPathTo(event.currentTarget)
|
27
|
+
action = `find(:xpath, '${path}').click`
|
28
|
+
} else {
|
29
|
+
return;
|
30
|
+
}
|
31
|
+
var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
|
32
|
+
testingOutput.push({action: action, target: target, options: options });
|
33
|
+
sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));
|
34
|
+
};
|
35
|
+
|
36
|
+
function keypressFunction(evt) {
|
37
|
+
evt = evt || window.event;
|
38
|
+
var charCode = evt.keyCode || evt.which;
|
39
|
+
var charStr = String.fromCharCode(charCode);
|
40
|
+
if (!evt.target.labels) {
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
var label = evt.target.labels[0].textContent;
|
44
|
+
var text = (evt.target.value + charStr).trim().replace("'", "\\\'");
|
45
|
+
var action = "fill_in";
|
46
|
+
var target = evt.target.labels[0].textContent;
|
47
|
+
var options = ", with: '" + text + "'";
|
48
|
+
var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
|
49
|
+
var lastAction = testingOutput[testingOutput.length - 1];
|
50
|
+
if (lastAction && lastAction.action == action && lastAction.target == "\'" + target + "\'") {
|
51
|
+
lastAction.options = options;
|
52
|
+
} else {
|
53
|
+
testingOutput.push({action: action, target: "\'" + target + "\'", options: options});
|
54
|
+
}
|
55
|
+
sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));
|
56
|
+
}
|
57
|
+
|
58
|
+
function keyDownFunction(evt){
|
59
|
+
if (evt.target.labels) {
|
60
|
+
return;
|
61
|
+
}
|
62
|
+
evt = evt || window.event;
|
63
|
+
var charCode = evt.keyCode || evt.which;
|
64
|
+
var charStr = capybaraFromCharCode(charCode);
|
65
|
+
var letter = evt.key == "'" ? "\\\'" : evt.key;
|
66
|
+
var tagName = evt.target.tagName.toLowerCase();
|
67
|
+
var action = finderForElement(evt.target) + "." // `find('${tagName}').`;
|
68
|
+
var target = ""
|
69
|
+
if (charStr) {
|
70
|
+
target = `send_keys(${charStr})`;
|
71
|
+
} else {
|
72
|
+
target = `send_keys('${letter}')`;
|
73
|
+
}
|
74
|
+
var options = "";
|
75
|
+
var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
|
76
|
+
var lastAction = testingOutput[testingOutput.length - 1];
|
77
|
+
// If the last key pressed was enter, always start a new action (otherwise with trix mentions, it happens too fast and we don't actually select the mentioned user correctly.)
|
78
|
+
if (lastAction && lastAction.target.substr(lastAction.target.length - 7 , 6) == ":enter") {
|
79
|
+
lastAction = null;
|
80
|
+
}
|
81
|
+
if (lastAction && lastAction.action == action && lastAction.target.substr(0,9) == 'send_keys') {
|
82
|
+
if (charStr) {
|
83
|
+
lastAction.target = lastAction.target.substr(0, lastAction.target.length - 1) + ', ' + charStr + ')'
|
84
|
+
} else {
|
85
|
+
if (lastAction.target.substr(lastAction.target.length - 2, 1) == "'") {
|
86
|
+
lastAction.target = lastAction.target.substr(0, lastAction.target.length - 2) + letter + '\'' + ')'
|
87
|
+
} else {
|
88
|
+
lastAction.target = lastAction.target.substr(0, lastAction.target.length - 1) + ', \'' + letter + '\'' + ')'
|
89
|
+
}
|
90
|
+
}
|
91
|
+
} else {
|
92
|
+
testingOutput.push({action: action, target: target, options: options});
|
93
|
+
}
|
94
|
+
sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));
|
95
|
+
}
|
96
|
+
|
97
|
+
function keyUpFunction(evt){
|
98
|
+
if (evt.target.labels) {
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
|
102
|
+
evt = evt || window.event;
|
103
|
+
var charCode = evt.keyCode || evt.which;
|
104
|
+
var charStr = capybaraKeyUpFromCharCode(charCode);
|
105
|
+
if (!charStr) {
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
var letter = String.fromCharCode(charCode);
|
109
|
+
var tagName = evt.target.tagName.toLowerCase();
|
110
|
+
var action = `find('${tagName}').`;
|
111
|
+
var target = ""
|
112
|
+
if (charStr) {
|
113
|
+
target = `send_keys(${charStr})`;
|
114
|
+
} else {
|
115
|
+
target = `send_keys('${letter}')`;
|
116
|
+
}
|
117
|
+
var options = "";
|
118
|
+
var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
|
119
|
+
var lastAction = testingOutput[testingOutput.length - 1];
|
120
|
+
if (lastAction && lastAction.action == action && lastAction.target.substr(0,9) == 'send_keys') {
|
121
|
+
if (charStr) {
|
122
|
+
lastAction.target = lastAction.target.substr(0, lastAction.target.length - 1) + ', ' + charStr + '' + ')'
|
123
|
+
} else {
|
124
|
+
lastAction.target = lastAction.target.substr(0, lastAction.target.length - 1) + ', \'' + letter + '\'' + ')'
|
125
|
+
}
|
126
|
+
} else {
|
127
|
+
testingOutput.push({action: action, target: target, options: options});
|
128
|
+
}
|
129
|
+
sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));
|
130
|
+
}
|
131
|
+
|
132
|
+
</script>
|
@@ -0,0 +1,50 @@
|
|
1
|
+
<script>
|
2
|
+
function capybaraFromCharCode(charCode) {
|
3
|
+
codes = {
|
4
|
+
8 : ':backspace',
|
5
|
+
9 : ':tab',
|
6
|
+
13 : ':enter',
|
7
|
+
16 : ':shift',
|
8
|
+
17 : ':control',
|
9
|
+
18 : ':alt',
|
10
|
+
19 : ':pause',
|
11
|
+
27 : ':escape',
|
12
|
+
// 32 : ':space',
|
13
|
+
33 : ':page_up',
|
14
|
+
34 : ':page_down',
|
15
|
+
35 : ':end',
|
16
|
+
36 : ':home',
|
17
|
+
37 : ':left',
|
18
|
+
38 : ':up',
|
19
|
+
39 : ':right',
|
20
|
+
40 : ':down',
|
21
|
+
45 : ':insert',
|
22
|
+
46 : ':delete',
|
23
|
+
91 : ':command',
|
24
|
+
112: ':f1',
|
25
|
+
113: ':f2',
|
26
|
+
114: ':f3',
|
27
|
+
115: ':f4',
|
28
|
+
116: ':f5',
|
29
|
+
117: ':f6',
|
30
|
+
118: ':f7',
|
31
|
+
119: ':f8',
|
32
|
+
120: ':f9',
|
33
|
+
121: ':f10',
|
34
|
+
122: ':f11',
|
35
|
+
123: ':f12',
|
36
|
+
}
|
37
|
+
return codes[charCode];
|
38
|
+
}
|
39
|
+
|
40
|
+
function capybaraKeyUpFromCharCode(charCode) {
|
41
|
+
codes = {
|
42
|
+
16 : ':shift',
|
43
|
+
17 : ':control',
|
44
|
+
18 : ':alt',
|
45
|
+
91 : ':command',
|
46
|
+
}
|
47
|
+
return codes[charCode];
|
48
|
+
}
|
49
|
+
|
50
|
+
</script>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<script>
|
2
|
+
// document.addEventListener('keydown', function(e){keyDownFunction(e)}, true);
|
3
|
+
// document.addEventListener('keyup', function(e){keyUpFunction(e)}, true);
|
4
|
+
document.addEventListener('keypress', function(e){keypressFunction(e)});
|
5
|
+
document.addEventListener('mouseover', function(evt){mutationStart(evt)}, true);
|
6
|
+
document.addEventListener('mouseover', function(){mutationEnd()}, false);
|
7
|
+
|
8
|
+
$(document).on('click', '*', function(event){clickFunction(event)});
|
9
|
+
</script>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<script>
|
2
|
+
|
3
|
+
function initializeMutationObserver(){
|
4
|
+
window.mutationObserver = new MutationObserver(function(mutations) {
|
5
|
+
console.log("Mutation observed")
|
6
|
+
if (!window.target) {
|
7
|
+
console.log("There is no window.target element. Quitting the mutation callback function");
|
8
|
+
return;
|
9
|
+
}
|
10
|
+
var options = "";
|
11
|
+
var targetClass = window.target.classList[0] ? `.${window.target.classList[0]}` : ""
|
12
|
+
var text = window.target.innerText ? `', text: '${window.target.innerText}` : ""
|
13
|
+
var action = `${finderForElement(window.target)}.hover`;
|
14
|
+
// var action = `find('${window.target.localName}${targetClass}${text}').hover`;
|
15
|
+
var target = "";
|
16
|
+
var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
|
17
|
+
testingOutput.push({action: action, target: target, options: options});
|
18
|
+
sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));
|
19
|
+
});
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
function mutationStart(evt) {
|
26
|
+
window.target = evt.target;
|
27
|
+
const opts = {attributes: true, characterData: true, childList: true, subtree: true}
|
28
|
+
window.mutationObserver.observe(document.documentElement, opts);
|
29
|
+
}
|
30
|
+
|
31
|
+
function mutationEnd () {
|
32
|
+
window.mutationObserver.disconnect();
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
</script>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<% if Rails.env.test? && ENV['MAGIC_TEST'].present? %>
|
2
|
+
<% unless MagicTest.jquery_already_included %>
|
3
|
+
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
|
4
|
+
<% end %>
|
5
|
+
|
6
|
+
<%= render 'magic_test/context_menu' %>
|
7
|
+
<%= render 'magic_test/key_codes' %>
|
8
|
+
<%= render 'magic_test/storage' %>
|
9
|
+
<%= render 'magic_test/finders' %>
|
10
|
+
<%= render 'magic_test/mutation_observer' %>
|
11
|
+
<%= render 'magic_test/javascript_helpers' %>
|
12
|
+
<%= render 'magic_test/listeners' %>
|
13
|
+
<% end %>
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "magic_test"
|
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,40 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'magic_test/engine'
|
3
|
+
|
4
|
+
module MagicTest
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
def self.source_paths
|
7
|
+
[MagicTest::Engine.root, File.expand_path('../templates', __FILE__)]
|
8
|
+
end
|
9
|
+
|
10
|
+
argument :jquery_already_included, :type => :string, :default => 'yes'
|
11
|
+
|
12
|
+
# Override the attr_accessor generated by 'argument' so that
|
13
|
+
# subscription_owner_model is always returned lowercase.
|
14
|
+
def jquery_already_included
|
15
|
+
@jquery_already_included.strip.downcase.first == 'y'
|
16
|
+
end
|
17
|
+
|
18
|
+
def install
|
19
|
+
unless defined?(MagicTest)
|
20
|
+
gem_group :test do
|
21
|
+
gem 'magic_test'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
template 'config/initializers/magic_test.rb'
|
26
|
+
|
27
|
+
generate 'system_test', 'basic'
|
28
|
+
gsub_file 'test/system/basics_test.rb', '# ', ''
|
29
|
+
gsub_file 'test/system/basics_test.rb', '#', ''
|
30
|
+
gsub_file 'test/system/basics_test.rb', 'visiting the index', 'getting started'
|
31
|
+
gsub_file 'test/system/basics_test.rb', 'visit basics_url', 'visit root_url'
|
32
|
+
gsub_file 'test/system/basics_test.rb', 'assert_selector "h1", text: "Basic"', 'magic_test'
|
33
|
+
|
34
|
+
gsub_file 'test/application_system_test_case.rb', 'using: :headless_chrome', "using: (ENV['SHOW_TESTS'] ? :chrome : :headless_chrome)"
|
35
|
+
gsub_file 'test/application_system_test_case.rb', 'using: :headless_firefox', "using: (ENV['SHOW_TESTS'] ? :firefox : :headless_firefox)"
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/magic_test.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "magic_test/version"
|
2
|
+
require "magic_test/railtie"
|
3
|
+
require "magic_test/engine"
|
4
|
+
require "magic_test/support"
|
5
|
+
|
6
|
+
module MagicTest
|
7
|
+
class Error < StandardError; end
|
8
|
+
|
9
|
+
mattr_accessor :jquery_already_included
|
10
|
+
@@jquery_already_included = false
|
11
|
+
|
12
|
+
def self.setup
|
13
|
+
yield self
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'magic_test/support'
|
2
|
+
|
3
|
+
module MagicTest
|
4
|
+
class Engine < Rails::Engine
|
5
|
+
config.after_initialize do
|
6
|
+
if ENV['MAGIC_TEST'].present?
|
7
|
+
if defined? ActionDispatch::SystemTestCase
|
8
|
+
ActionDispatch::SystemTestCase.include MagicTest::Support
|
9
|
+
end
|
10
|
+
|
11
|
+
if defined? ActionDispatch::IntegrationTest
|
12
|
+
ActionDispatch::IntegrationTest.include MagicTest::Support
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module MagicTest
|
2
|
+
module Support
|
3
|
+
def assert_selected_exists
|
4
|
+
selected_text = page.evaluate_script("window.selectedText()")
|
5
|
+
return if selected_text.blank?
|
6
|
+
filepath, line = caller.select { |s| s.include?("/test/") }.reject { |s| s.include?("helper") }.first.split(':')
|
7
|
+
contents = File.open(filepath).read.lines
|
8
|
+
chunks = contents.each_slice(line.to_i - 1 + @test_lines_written).to_a
|
9
|
+
indentation = chunks[1].first.match(/^(\s*)/)[0]
|
10
|
+
chunks.first << indentation + "assert(page.has_content?('#{selected_text.gsub("'", "\\\\'")}'))" + "\n"
|
11
|
+
@test_lines_written += 1
|
12
|
+
contents = chunks.flatten.join
|
13
|
+
File.open(filepath, 'w') do |file|
|
14
|
+
file.puts(contents)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def track_keystrokes
|
19
|
+
page.evaluate_script("trackKeystrokes()")
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_last
|
23
|
+
history_lines = Readline::HISTORY.to_a.last(20)
|
24
|
+
i = 2
|
25
|
+
last = history_lines.last(2).first
|
26
|
+
last_block = [last]
|
27
|
+
if last == 'end' || last.first(4) == 'end '
|
28
|
+
i += 1
|
29
|
+
last_block.unshift(history_lines.last(i).first)
|
30
|
+
until !last_block.first.match(/^(\s+)/)&[0] do
|
31
|
+
i += 1
|
32
|
+
last_block.unshift(history_lines.last(i).first)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
return last_block
|
36
|
+
end
|
37
|
+
|
38
|
+
def flush
|
39
|
+
filepath, line = caller.select { |s| s.include?("/test/") }.reject { |s| s.include?("helper") }.first.split(':')
|
40
|
+
contents = File.open(filepath).read.lines
|
41
|
+
chunks = contents.each_slice(line.to_i - 1 + @test_lines_written).to_a
|
42
|
+
indentation = chunks[1].first.match(/^(\s*)/)[0]
|
43
|
+
output = page.evaluate_script("JSON.parse(sessionStorage.getItem('testingOutput'))")
|
44
|
+
puts
|
45
|
+
puts "javascript recorded on the front-end looks like this:"
|
46
|
+
puts output
|
47
|
+
puts
|
48
|
+
puts "(writing that to `#{filepath}`.)"
|
49
|
+
if output
|
50
|
+
output.each do |last|
|
51
|
+
chunks.first << indentation + "#{last['action']} #{last['target']}#{last['options']}" + "\n"
|
52
|
+
@test_lines_written += 1
|
53
|
+
end
|
54
|
+
contents = chunks.flatten.join
|
55
|
+
File.open(filepath, 'w') do |file|
|
56
|
+
file.puts(contents)
|
57
|
+
end
|
58
|
+
# clear the testing output now.
|
59
|
+
empty_cache
|
60
|
+
else
|
61
|
+
puts "`window.testingOutput` was empty in the browser. Something must be wrong on the browser side."
|
62
|
+
end
|
63
|
+
return true
|
64
|
+
end
|
65
|
+
|
66
|
+
def ok
|
67
|
+
filepath, line = caller.select { |s| s.include?("/test/") }.reject { |s| s.include?("helper") }.first.split(':')
|
68
|
+
puts "(writing that to `#{filepath}`.)"
|
69
|
+
contents = File.open(filepath).read.lines
|
70
|
+
chunks = contents.each_slice(line.to_i - 1 + @test_lines_written).to_a
|
71
|
+
indentation = chunks[1].first.match(/^(\s*)/)[0]
|
72
|
+
get_last.each do |last|
|
73
|
+
chunks.first << indentation + last + "\n"
|
74
|
+
@test_lines_written += 1
|
75
|
+
end
|
76
|
+
contents = chunks.flatten.join
|
77
|
+
File.open(filepath, 'w') do |file|
|
78
|
+
file.puts(contents)
|
79
|
+
end
|
80
|
+
return true
|
81
|
+
end
|
82
|
+
|
83
|
+
def empty_cache
|
84
|
+
page.evaluate_script("sessionStorage.setItem('testingOutput', JSON.stringify([]))")
|
85
|
+
end
|
86
|
+
|
87
|
+
def magic_test
|
88
|
+
empty_cache
|
89
|
+
@test_lines_written = 0
|
90
|
+
begin
|
91
|
+
binding.pry
|
92
|
+
rescue
|
93
|
+
retry
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/magic_test.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "magic_test/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "magic_test"
|
8
|
+
spec.version = MagicTest::VERSION
|
9
|
+
spec.authors = ["Andrew Culver", "Adam Pallozzi"]
|
10
|
+
spec.email = ["andrew.culver@gmail.com", "adampallozzi@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Create system tests interactively.}
|
13
|
+
spec.homepage = "https://github.com/bullet-train/magic_test"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
26
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
27
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
+
|
29
|
+
spec.add_dependency "pry"
|
30
|
+
spec.add_dependency "capybara", "~> 3.0"
|
31
|
+
spec.add_dependency "rails", "~> 6.0"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: magic_test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Culver
|
8
|
+
- Adam Pallozzi
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2021-02-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '13.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '13.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '5.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '5.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: pry
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: capybara
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rails
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '6.0'
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '6.0'
|
98
|
+
description:
|
99
|
+
email:
|
100
|
+
- andrew.culver@gmail.com
|
101
|
+
- adampallozzi@gmail.com
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- ".travis.yml"
|
108
|
+
- CODE_OF_CONDUCT.md
|
109
|
+
- Gemfile
|
110
|
+
- Gemfile.lock
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- app/views/magic_test/_context_menu.html
|
115
|
+
- app/views/magic_test/_finders.html
|
116
|
+
- app/views/magic_test/_javascript_helpers.html
|
117
|
+
- app/views/magic_test/_key_codes.html
|
118
|
+
- app/views/magic_test/_listeners.html
|
119
|
+
- app/views/magic_test/_mutation_observer.html
|
120
|
+
- app/views/magic_test/_storage.html
|
121
|
+
- app/views/magic_test/_support.html.erb
|
122
|
+
- bin/console
|
123
|
+
- bin/setup
|
124
|
+
- lib/generators/magic_test/install_generator.rb
|
125
|
+
- lib/generators/magic_test/templates/config/initializers/magic_test.rb
|
126
|
+
- lib/magic_test.rb
|
127
|
+
- lib/magic_test/engine.rb
|
128
|
+
- lib/magic_test/railtie.rb
|
129
|
+
- lib/magic_test/support.rb
|
130
|
+
- lib/magic_test/version.rb
|
131
|
+
- lib/tasks/magic_test.rake
|
132
|
+
- magic_test.gemspec
|
133
|
+
homepage: https://github.com/bullet-train/magic_test
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubygems_version: 3.1.4
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: Create system tests interactively.
|
156
|
+
test_files: []
|