magic_test 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +84 -80
- data/LICENSE.txt +1 -1
- data/README.md +24 -11
- data/app/views/magic_test/_context_menu.html.erb +90 -0
- data/bin/rails +14 -0
- data/exe/magic +38 -0
- data/lib/generators/magic_test/install_generator.rb +55 -8
- data/lib/magic_test/version.rb +1 -1
- data/magic_test.gemspec +1 -1
- metadata +10 -7
- data/app/views/magic_test/_context_menu.html +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 015de5e14bc97d6b2c2b878fbac4a9e77bce655e1d76c34ef5c8c8f294d4ebfe
|
4
|
+
data.tar.gz: 9e4097db71f6a09517a78a68da450606c4a06413da6ddeef2ca921f9c4009be8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac6f104c5be822130351be8222231a85ba0512c7a9db07e00938942341df7fc18a12e0f764fc1f81a0e3c83fc251d3d2f3f0f021ae7dd3fa6d7b1359ae488759
|
7
|
+
data.tar.gz: 0647614ed4b0a9ed3882dafeadf668c0b27b7d185eff280079b7bd6dc3512183e68f5c6f3720f7cf6d6a509dae5d631a2ee247e9d9e985da66c20c66e9d3d233
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,87 +1,87 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
magic_test (0.0
|
4
|
+
magic_test (0.1.0)
|
5
5
|
capybara (>= 3.0)
|
6
6
|
pry
|
7
7
|
pry-stack_explorer
|
8
|
-
rails (>=
|
8
|
+
rails (>= 5.0)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
actioncable (7.0.2.
|
14
|
-
actionpack (= 7.0.2.
|
15
|
-
activesupport (= 7.0.2.
|
13
|
+
actioncable (7.0.2.3)
|
14
|
+
actionpack (= 7.0.2.3)
|
15
|
+
activesupport (= 7.0.2.3)
|
16
16
|
nio4r (~> 2.0)
|
17
17
|
websocket-driver (>= 0.6.1)
|
18
|
-
actionmailbox (7.0.2.
|
19
|
-
actionpack (= 7.0.2.
|
20
|
-
activejob (= 7.0.2.
|
21
|
-
activerecord (= 7.0.2.
|
22
|
-
activestorage (= 7.0.2.
|
23
|
-
activesupport (= 7.0.2.
|
18
|
+
actionmailbox (7.0.2.3)
|
19
|
+
actionpack (= 7.0.2.3)
|
20
|
+
activejob (= 7.0.2.3)
|
21
|
+
activerecord (= 7.0.2.3)
|
22
|
+
activestorage (= 7.0.2.3)
|
23
|
+
activesupport (= 7.0.2.3)
|
24
24
|
mail (>= 2.7.1)
|
25
25
|
net-imap
|
26
26
|
net-pop
|
27
27
|
net-smtp
|
28
|
-
actionmailer (7.0.2.
|
29
|
-
actionpack (= 7.0.2.
|
30
|
-
actionview (= 7.0.2.
|
31
|
-
activejob (= 7.0.2.
|
32
|
-
activesupport (= 7.0.2.
|
28
|
+
actionmailer (7.0.2.3)
|
29
|
+
actionpack (= 7.0.2.3)
|
30
|
+
actionview (= 7.0.2.3)
|
31
|
+
activejob (= 7.0.2.3)
|
32
|
+
activesupport (= 7.0.2.3)
|
33
33
|
mail (~> 2.5, >= 2.5.4)
|
34
34
|
net-imap
|
35
35
|
net-pop
|
36
36
|
net-smtp
|
37
37
|
rails-dom-testing (~> 2.0)
|
38
|
-
actionpack (7.0.2.
|
39
|
-
actionview (= 7.0.2.
|
40
|
-
activesupport (= 7.0.2.
|
38
|
+
actionpack (7.0.2.3)
|
39
|
+
actionview (= 7.0.2.3)
|
40
|
+
activesupport (= 7.0.2.3)
|
41
41
|
rack (~> 2.0, >= 2.2.0)
|
42
42
|
rack-test (>= 0.6.3)
|
43
43
|
rails-dom-testing (~> 2.0)
|
44
44
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
45
|
-
actiontext (7.0.2.
|
46
|
-
actionpack (= 7.0.2.
|
47
|
-
activerecord (= 7.0.2.
|
48
|
-
activestorage (= 7.0.2.
|
49
|
-
activesupport (= 7.0.2.
|
45
|
+
actiontext (7.0.2.3)
|
46
|
+
actionpack (= 7.0.2.3)
|
47
|
+
activerecord (= 7.0.2.3)
|
48
|
+
activestorage (= 7.0.2.3)
|
49
|
+
activesupport (= 7.0.2.3)
|
50
50
|
globalid (>= 0.6.0)
|
51
51
|
nokogiri (>= 1.8.5)
|
52
|
-
actionview (7.0.2.
|
53
|
-
activesupport (= 7.0.2.
|
52
|
+
actionview (7.0.2.3)
|
53
|
+
activesupport (= 7.0.2.3)
|
54
54
|
builder (~> 3.1)
|
55
55
|
erubi (~> 1.4)
|
56
56
|
rails-dom-testing (~> 2.0)
|
57
57
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
58
|
-
activejob (7.0.2.
|
59
|
-
activesupport (= 7.0.2.
|
58
|
+
activejob (7.0.2.3)
|
59
|
+
activesupport (= 7.0.2.3)
|
60
60
|
globalid (>= 0.3.6)
|
61
|
-
activemodel (7.0.2.
|
62
|
-
activesupport (= 7.0.2.
|
63
|
-
activerecord (7.0.2.
|
64
|
-
activemodel (= 7.0.2.
|
65
|
-
activesupport (= 7.0.2.
|
66
|
-
activestorage (7.0.2.
|
67
|
-
actionpack (= 7.0.2.
|
68
|
-
activejob (= 7.0.2.
|
69
|
-
activerecord (= 7.0.2.
|
70
|
-
activesupport (= 7.0.2.
|
61
|
+
activemodel (7.0.2.3)
|
62
|
+
activesupport (= 7.0.2.3)
|
63
|
+
activerecord (7.0.2.3)
|
64
|
+
activemodel (= 7.0.2.3)
|
65
|
+
activesupport (= 7.0.2.3)
|
66
|
+
activestorage (7.0.2.3)
|
67
|
+
actionpack (= 7.0.2.3)
|
68
|
+
activejob (= 7.0.2.3)
|
69
|
+
activerecord (= 7.0.2.3)
|
70
|
+
activesupport (= 7.0.2.3)
|
71
71
|
marcel (~> 1.0)
|
72
72
|
mini_mime (>= 1.1.0)
|
73
|
-
activesupport (7.0.2.
|
73
|
+
activesupport (7.0.2.3)
|
74
74
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
75
75
|
i18n (>= 1.6, < 2)
|
76
76
|
minitest (>= 5.1)
|
77
77
|
tzinfo (~> 2.0)
|
78
|
-
addressable (2.8.
|
79
|
-
public_suffix (>= 2.0.2, <
|
78
|
+
addressable (2.8.1)
|
79
|
+
public_suffix (>= 2.0.2, < 6.0)
|
80
80
|
ast (2.4.2)
|
81
81
|
binding_of_caller (1.0.0)
|
82
82
|
debug_inspector (>= 0.0.1)
|
83
83
|
builder (3.2.4)
|
84
|
-
capybara (3.
|
84
|
+
capybara (3.38.0)
|
85
85
|
addressable
|
86
86
|
matrix
|
87
87
|
mini_mime (>= 0.1.3)
|
@@ -93,46 +93,40 @@ GEM
|
|
93
93
|
coderay (1.1.3)
|
94
94
|
concurrent-ruby (1.1.9)
|
95
95
|
crass (1.0.6)
|
96
|
+
date (3.3.2)
|
96
97
|
debug_inspector (1.1.0)
|
97
|
-
digest (3.1.0)
|
98
98
|
erubi (1.10.0)
|
99
99
|
globalid (1.0.0)
|
100
100
|
activesupport (>= 5.0)
|
101
101
|
i18n (1.10.0)
|
102
102
|
concurrent-ruby (~> 1.0)
|
103
|
-
io-wait (0.2.1)
|
104
103
|
loofah (2.14.0)
|
105
104
|
crass (~> 1.0.2)
|
106
105
|
nokogiri (>= 1.5.9)
|
107
|
-
mail (2.
|
106
|
+
mail (2.8.0)
|
108
107
|
mini_mime (>= 0.1.1)
|
108
|
+
net-imap
|
109
|
+
net-pop
|
110
|
+
net-smtp
|
109
111
|
marcel (1.0.2)
|
110
112
|
matrix (0.4.2)
|
111
113
|
method_source (1.0.0)
|
112
114
|
mini_mime (1.1.2)
|
113
115
|
mini_portile2 (2.8.0)
|
114
116
|
minitest (5.15.0)
|
115
|
-
net-imap (0.2
|
116
|
-
|
117
|
+
net-imap (0.3.2)
|
118
|
+
date
|
117
119
|
net-protocol
|
118
|
-
|
119
|
-
net-pop (0.1.1)
|
120
|
-
digest
|
120
|
+
net-pop (0.1.2)
|
121
121
|
net-protocol
|
122
|
+
net-protocol (0.2.1)
|
122
123
|
timeout
|
123
|
-
net-
|
124
|
-
io-wait
|
125
|
-
timeout
|
126
|
-
net-smtp (0.3.1)
|
127
|
-
digest
|
124
|
+
net-smtp (0.3.3)
|
128
125
|
net-protocol
|
129
|
-
|
130
|
-
nio4r (2.5.8)
|
126
|
+
nio4r (2.5.9)
|
131
127
|
nokogiri (1.13.3)
|
132
128
|
mini_portile2 (~> 2.8.0)
|
133
129
|
racc (~> 1.4)
|
134
|
-
nokogiri (1.13.3-x86_64-darwin)
|
135
|
-
racc (~> 1.4)
|
136
130
|
parallel (1.21.0)
|
137
131
|
parser (3.0.3.2)
|
138
132
|
ast (~> 2.4.1)
|
@@ -142,33 +136,33 @@ GEM
|
|
142
136
|
pry-stack_explorer (0.6.1)
|
143
137
|
binding_of_caller (~> 1.0)
|
144
138
|
pry (~> 0.13)
|
145
|
-
public_suffix (
|
139
|
+
public_suffix (5.0.1)
|
146
140
|
racc (1.6.0)
|
147
141
|
rack (2.2.3)
|
148
142
|
rack-test (1.1.0)
|
149
143
|
rack (>= 1.0, < 3)
|
150
|
-
rails (7.0.2.
|
151
|
-
actioncable (= 7.0.2.
|
152
|
-
actionmailbox (= 7.0.2.
|
153
|
-
actionmailer (= 7.0.2.
|
154
|
-
actionpack (= 7.0.2.
|
155
|
-
actiontext (= 7.0.2.
|
156
|
-
actionview (= 7.0.2.
|
157
|
-
activejob (= 7.0.2.
|
158
|
-
activemodel (= 7.0.2.
|
159
|
-
activerecord (= 7.0.2.
|
160
|
-
activestorage (= 7.0.2.
|
161
|
-
activesupport (= 7.0.2.
|
144
|
+
rails (7.0.2.3)
|
145
|
+
actioncable (= 7.0.2.3)
|
146
|
+
actionmailbox (= 7.0.2.3)
|
147
|
+
actionmailer (= 7.0.2.3)
|
148
|
+
actionpack (= 7.0.2.3)
|
149
|
+
actiontext (= 7.0.2.3)
|
150
|
+
actionview (= 7.0.2.3)
|
151
|
+
activejob (= 7.0.2.3)
|
152
|
+
activemodel (= 7.0.2.3)
|
153
|
+
activerecord (= 7.0.2.3)
|
154
|
+
activestorage (= 7.0.2.3)
|
155
|
+
activesupport (= 7.0.2.3)
|
162
156
|
bundler (>= 1.15.0)
|
163
|
-
railties (= 7.0.2.
|
157
|
+
railties (= 7.0.2.3)
|
164
158
|
rails-dom-testing (2.0.3)
|
165
159
|
activesupport (>= 4.2.0)
|
166
160
|
nokogiri (>= 1.6)
|
167
161
|
rails-html-sanitizer (1.4.2)
|
168
162
|
loofah (~> 2.3)
|
169
|
-
railties (7.0.2.
|
170
|
-
actionpack (= 7.0.2.
|
171
|
-
activesupport (= 7.0.2.
|
163
|
+
railties (7.0.2.3)
|
164
|
+
actionpack (= 7.0.2.3)
|
165
|
+
activesupport (= 7.0.2.3)
|
172
166
|
method_source
|
173
167
|
rake (>= 12.2)
|
174
168
|
thor (~> 1.0)
|
@@ -192,12 +186,20 @@ GEM
|
|
192
186
|
rubocop (>= 1.7.0, < 2.0)
|
193
187
|
rubocop-ast (>= 0.4.0)
|
194
188
|
ruby-progressbar (1.11.0)
|
189
|
+
sprockets (4.1.1)
|
190
|
+
concurrent-ruby (~> 1.0)
|
191
|
+
rack (> 1, < 3)
|
192
|
+
sprockets-rails (3.4.2)
|
193
|
+
actionpack (>= 5.2)
|
194
|
+
activesupport (>= 5.2)
|
195
|
+
sprockets (>= 3.0.0)
|
196
|
+
sqlite3 (1.5.4)
|
197
|
+
mini_portile2 (~> 2.8.0)
|
195
198
|
standard (1.5.0)
|
196
199
|
rubocop (= 1.23.0)
|
197
200
|
rubocop-performance (= 1.12.0)
|
198
|
-
strscan (3.0.1)
|
199
201
|
thor (1.2.1)
|
200
|
-
timeout (0.
|
202
|
+
timeout (0.3.1)
|
201
203
|
tzinfo (2.0.4)
|
202
204
|
concurrent-ruby (~> 1.0)
|
203
205
|
unicode-display_width (2.1.0)
|
@@ -206,7 +208,7 @@ GEM
|
|
206
208
|
websocket-extensions (0.1.5)
|
207
209
|
xpath (3.2.0)
|
208
210
|
nokogiri (~> 1.8)
|
209
|
-
zeitwerk (2.
|
211
|
+
zeitwerk (2.6.6)
|
210
212
|
|
211
213
|
PLATFORMS
|
212
214
|
ruby
|
@@ -217,7 +219,9 @@ DEPENDENCIES
|
|
217
219
|
magic_test!
|
218
220
|
minitest (>= 5.0)
|
219
221
|
rake (>= 13.0)
|
222
|
+
sprockets-rails
|
223
|
+
sqlite3
|
220
224
|
standard
|
221
225
|
|
222
226
|
BUNDLED WITH
|
223
|
-
2.
|
227
|
+
2.5.10
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -8,9 +8,7 @@ Magic Test was created by [Andrew Culver](http://twitter.com/andrewculver) and [
|
|
8
8
|
|
9
9
|
## Sponsored By
|
10
10
|
|
11
|
-
<a href="https://bullettrain.co" target="_blank">
|
12
|
-
<img src="https://github.com/CanCanCommunity/cancancan/raw/develop/logo/bullet_train.png" alt="Bullet Train" width="400"/>
|
13
|
-
</a>
|
11
|
+
<a href="https://bullettrain.co" target="_blank"><img src="https://github.com/CanCanCommunity/cancancan/raw/develop/logo/bullet_train.png" alt="Bullet Train" width="400"/></a>
|
14
12
|
<br/>
|
15
13
|
<br/>
|
16
14
|
|
@@ -38,15 +36,26 @@ rails g magic_test:install
|
|
38
36
|
|
39
37
|
With this we will:
|
40
38
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
- Create a sample system test at `test/system/basics_test.rb` that invokes Magic Test via the `magic_test` method.
|
40
|
+
- Update your configuration to run a visible browser test if `MAGIC_TEST=1` is set as an environment variable, and a headless browser setting if the environment variable is not present.
|
41
|
+
- Insert a snippet to render a partial before any closing `</head>` tags in your `*.html.erb` views within the `app/views/layouts` directory.
|
42
|
+
> If you have any views containing `<head></head>` tags then please place this snippet so Magic Test can work accordingly.
|
45
43
|
|
46
44
|
```ruby+erb
|
47
45
|
<%= render 'magic_test/support' if Rails.env.test? %>
|
48
46
|
```
|
49
47
|
|
48
|
+
Generate binstubs by running `bundle binstubs magic_test` in the root of your Rails application. Now you'll be able to run Magic Test
|
49
|
+
with the following command:
|
50
|
+
|
51
|
+
```
|
52
|
+
bin/magic test test/system/basics_test.rb # for MiniTest
|
53
|
+
bin/magic spec spec/system/basics_spec.rb # for RSpec
|
54
|
+
```
|
55
|
+
|
56
|
+
The bin executable is implicitly running your Rails test with an environment variable that Magic Test looks for.
|
57
|
+
The full command looks like this: `MAGIC_TEST=1 rails test test/system/basics_test.rb`.
|
58
|
+
|
50
59
|
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!
|
51
60
|
|
52
61
|
## Usage
|
@@ -54,7 +63,7 @@ You should be done now! To review what we’ve done for you, be sure to do a `gi
|
|
54
63
|
### Running the Example Test
|
55
64
|
|
56
65
|
1. Open `test/system/basics_test.rb` in your editor of choice.
|
57
|
-
2. Run `
|
66
|
+
2. Run `bin/magic test test/system/basics_test.rb` on your shell.
|
58
67
|
|
59
68
|
This results in three windows:
|
60
69
|
|
@@ -62,7 +71,7 @@ This results in three windows:
|
|
62
71
|
2. **A browser** where you can click around the application and have your actions automatically converted into Capybara code.
|
63
72
|
3. **A editor** where you mostly just watch test code appear magically, but you can also edit it by hand should you need to.
|
64
73
|
|
65
|
-
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.
|
74
|
+
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. The browser will always open to the left at a width of 800 pixels. This is done so you can set up your other windows just once and expect your browser to appear in the same place during every test.
|
66
75
|
|
67
76
|
> #### Using Magic Test in New or Existing Tests
|
68
77
|
> 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.
|
@@ -73,7 +82,7 @@ You’re now free to issue Capybara commands in the debugger and see their resul
|
|
73
82
|
|
74
83
|
When you’re done writing the test interactively, you can press <kbd>Control</kbd> + <kbd>D</kbd> to finish running the test.
|
75
84
|
|
76
|
-
You can re-run `MAGIC_TEST=1 rails test
|
85
|
+
You can re-run `MAGIC_TEST=1 rails test test/system/basics_test.rb` or `bin/magic test 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.
|
77
86
|
|
78
87
|
When you’re actually done writing the test, be sure to remove the `magic_test` reference in the test file.
|
79
88
|
|
@@ -85,7 +94,11 @@ You can click on buttons, click on links, fill in forms, and do many other thing
|
|
85
94
|
|
86
95
|
### Generating Assertions in the Browser
|
87
96
|
|
88
|
-
|
97
|
+
#### Method 1:
|
98
|
+
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 a confirm dialog asking for if you want to move forward with the assertion or cancel.
|
99
|
+
|
100
|
+
#### Method 2:
|
101
|
+
You can now generate assertions by selecting your text and right-clicking with your mouse or touchpad.
|
89
102
|
|
90
103
|
### Flushing In Browser Actions and Assertions to the Test File
|
91
104
|
|
@@ -0,0 +1,90 @@
|
|
1
|
+
<script>
|
2
|
+
function ready(fn) {
|
3
|
+
if (document.readyState !== 'loading'){
|
4
|
+
fn();
|
5
|
+
} else {
|
6
|
+
document.addEventListener('DOMContentLoaded', fn);
|
7
|
+
}
|
8
|
+
}
|
9
|
+
|
10
|
+
ready(function() {
|
11
|
+
enableKeyboardShortcuts();
|
12
|
+
});
|
13
|
+
|
14
|
+
|
15
|
+
function enableKeyboardShortcuts() {
|
16
|
+
// Ctrl+A to generate an assertion
|
17
|
+
function keydown(event) {
|
18
|
+
if (event.ctrlKey && event.shiftKey && event.key === 'A') {
|
19
|
+
event.preventDefault();
|
20
|
+
generateAssertion();
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
document.addEventListener('keydown', keydown, false);
|
25
|
+
|
26
|
+
function generateAssertion() {
|
27
|
+
var text = selectedText().trim();
|
28
|
+
if (text.length > 0) {
|
29
|
+
var action = assertMethod() + text.replace("'", "\\\'") + "'";
|
30
|
+
var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
|
31
|
+
var target = "";
|
32
|
+
var options = "";
|
33
|
+
var accept = "You selected:\n\r" + text + "\n\rOk: Type `flush` into debugger console to add to test.\nCancel: To select new text."
|
34
|
+
if (window.confirm(accept)) {
|
35
|
+
testingOutput.push({action: action, target: target, options: options});
|
36
|
+
sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));
|
37
|
+
}
|
38
|
+
else {
|
39
|
+
console.log("Assertion was not generated.")
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
// Right-click to generate an assertion
|
45
|
+
function riteklick(event) {
|
46
|
+
if (event.button == 2) {
|
47
|
+
window.addEventListener("contextmenu", e => e.preventDefault());
|
48
|
+
setupAssertion(event);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
document.addEventListener('mousedown', riteklick);
|
53
|
+
|
54
|
+
function setupAssertion(event) {
|
55
|
+
var text = selectedText().trim();
|
56
|
+
if (text.length > 0) {
|
57
|
+
var action = assertMethod() + text.replace("'", "\\\'") + "'";
|
58
|
+
var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
|
59
|
+
var target = "";
|
60
|
+
var options = "";
|
61
|
+
var accept = "You selected:\n\r" + text + "\n\rOk: Type `flush` into debugger console to add to test.\nCancel: To select new text."
|
62
|
+
if (window.confirm(accept)) {
|
63
|
+
testingOutput.push({action: action, target: target, options: options});
|
64
|
+
sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));
|
65
|
+
}
|
66
|
+
else {
|
67
|
+
console.log("Assertion was not generated.")
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
function assertMethod(){
|
73
|
+
<%- if defined? RSpec %>
|
74
|
+
return "expect(page).to have_content '"
|
75
|
+
<%- else %>
|
76
|
+
return "assert page.has_content? '"
|
77
|
+
<%- end %>
|
78
|
+
}
|
79
|
+
|
80
|
+
function selectedText() {
|
81
|
+
var text = "";
|
82
|
+
if (window.getSelection) {
|
83
|
+
text = window.getSelection().toString();
|
84
|
+
} else if (document.selection && document.selection.type != "Control") {
|
85
|
+
text = document.selection.createRange().text;
|
86
|
+
}
|
87
|
+
return text;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
</script>
|
data/bin/rails
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path("..", __dir__)
|
6
|
+
ENGINE_PATH = File.expand_path("../lib/magic_test/engine", __dir__)
|
7
|
+
APP_PATH = File.expand_path("../test/dummy/config/application", __dir__)
|
8
|
+
|
9
|
+
# Set up gems listed in the Gemfile.
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
11
|
+
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
12
|
+
|
13
|
+
require "rails/all"
|
14
|
+
require "rails/engine/commands"
|
data/exe/magic
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
option = ARGV[0]
|
4
|
+
file_path = ARGV[1]
|
5
|
+
|
6
|
+
def run_magic_test(suite, option, file_path)
|
7
|
+
system("MAGIC_TEST=1 #{suite} #{option} #{file_path}")
|
8
|
+
end
|
9
|
+
|
10
|
+
case option
|
11
|
+
when "test"
|
12
|
+
suite = "rails"
|
13
|
+
run_magic_test(suite, option, file_path)
|
14
|
+
when "spec"
|
15
|
+
suite = "rspec"
|
16
|
+
run_magic_test(suite, option, file_path)
|
17
|
+
when "--help"
|
18
|
+
help_info = %q(
|
19
|
+
Usage: `bin/magic [option] [path/to/file]`
|
20
|
+
|
21
|
+
option = 'test' # will run MiniTest
|
22
|
+
option = 'spec' # will run RSpec
|
23
|
+
|
24
|
+
Assign `file_path` to the path of the file you want to test
|
25
|
+
|
26
|
+
Each run will implicitly pass the `MAGIC_TEST=1` environment variable in order to run Magic Test and it's debugger
|
27
|
+
)
|
28
|
+
|
29
|
+
puts help_info
|
30
|
+
else
|
31
|
+
quick_tip = %q(
|
32
|
+
To run Magic Test: `bin/magic [option] [path/to/file.rb]`
|
33
|
+
|
34
|
+
Run `bin/magic --help` for more information
|
35
|
+
)
|
36
|
+
|
37
|
+
puts quick_tip
|
38
|
+
end
|
@@ -14,15 +14,62 @@ module MagicTest
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
create_sample_test
|
18
|
+
update_config_file
|
19
|
+
update_layout_templates
|
20
|
+
show_install_message
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def create_sample_test
|
17
26
|
generate "system_test", "basic"
|
18
|
-
|
19
|
-
gsub_file
|
20
|
-
gsub_file
|
21
|
-
gsub_file
|
22
|
-
gsub_file
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
test_file = "test/system/basics_test.rb"
|
28
|
+
gsub_file test_file, "# ", ""
|
29
|
+
gsub_file test_file, "#", ""
|
30
|
+
gsub_file test_file, "visiting the index", "getting started"
|
31
|
+
gsub_file test_file, "visit basics_url", "visit root_path"
|
32
|
+
gsub_file test_file, 'assert_selector "h1", text: "Basic"', "magic_test"
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_config_file
|
36
|
+
config_file = "test/application_system_test_case.rb"
|
37
|
+
|
38
|
+
gsub_file config_file, "using: :chrome", "using: :headless_chrome"
|
39
|
+
gsub_file config_file, "using: :firefox", "using: :headless_firefox"
|
40
|
+
|
41
|
+
gsub_file config_file, "using: :headless_chrome", "using: (ENV['MAGIC_TEST'] ? :chrome : :headless_chrome)"
|
42
|
+
gsub_file config_file, "using: :headless_firefox", "using: (ENV['MAGIC_TEST'] ? :firefox : :headless_firefox)"
|
43
|
+
|
44
|
+
gsub_file config_file, "screen_size: [1400, 1400]", "screen_size: (ENV['MAGIC_TEST'] ? [800, 1400] : [1400, 1400])"
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_layout_templates
|
48
|
+
templates = layout_templates
|
49
|
+
string = " <%= render 'magic_test/support' if Rails.env.test? %>\n"
|
50
|
+
templates.each do |file|
|
51
|
+
insert_into_file file, string, before: /^\s*<\/head>/
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def layout_templates
|
56
|
+
layouts = Dir.glob("#{Rails.root}/app/views/layouts/**/*.html.erb")
|
57
|
+
layouts.reject { |file| file =~ /mailer/ }
|
58
|
+
end
|
59
|
+
|
60
|
+
def show_install_message
|
61
|
+
message = %q(
|
62
|
+
We just inserted:
|
63
|
+
`<%= render 'magic_test/support' if Rails.env.test? %>`
|
64
|
+
before each closing `</head>` tag in your all of your templates in your `layouts` directory.
|
65
|
+
If there is another template or partial containing any `<head></head>` tags any where else in
|
66
|
+
your project (Example: `views/shared/_head.html.erb`), please paste the render snippet above within the head tags to ensure Magic Test
|
67
|
+
will work as expected.
|
68
|
+
Run your first Magic Test by typing `MAGIC_TEST=1 rails test test/system/basics_test.rb` or generate an executable
|
69
|
+
with `bundle binstubs magic_test` and then run `bin/magic test test/system/basics_test.rb` into your terminal!
|
70
|
+
)
|
71
|
+
|
72
|
+
puts message
|
26
73
|
end
|
27
74
|
end
|
28
75
|
end
|
data/lib/magic_test/version.rb
CHANGED
data/magic_test.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magic_test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -115,19 +115,20 @@ dependencies:
|
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
118
|
+
version: '5.0'
|
119
119
|
type: :runtime
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
125
|
+
version: '5.0'
|
126
126
|
description:
|
127
127
|
email:
|
128
128
|
- andrew.culver@gmail.com
|
129
129
|
- adampallozzi@gmail.com
|
130
|
-
executables:
|
130
|
+
executables:
|
131
|
+
- magic
|
131
132
|
extensions: []
|
132
133
|
extra_rdoc_files: []
|
133
134
|
files:
|
@@ -140,7 +141,7 @@ files:
|
|
140
141
|
- LICENSE.txt
|
141
142
|
- README.md
|
142
143
|
- Rakefile
|
143
|
-
- app/views/magic_test/_context_menu.html
|
144
|
+
- app/views/magic_test/_context_menu.html.erb
|
144
145
|
- app/views/magic_test/_finders.html
|
145
146
|
- app/views/magic_test/_javascript_helpers.html
|
146
147
|
- app/views/magic_test/_key_codes.html
|
@@ -149,7 +150,9 @@ files:
|
|
149
150
|
- app/views/magic_test/_storage.html
|
150
151
|
- app/views/magic_test/_support.html.erb
|
151
152
|
- bin/console
|
153
|
+
- bin/rails
|
152
154
|
- bin/setup
|
155
|
+
- exe/magic
|
153
156
|
- lib/generators/magic_test/install_generator.rb
|
154
157
|
- lib/magic_test.rb
|
155
158
|
- lib/magic_test/engine.rb
|
@@ -177,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
180
|
- !ruby/object:Gem::Version
|
178
181
|
version: '0'
|
179
182
|
requirements: []
|
180
|
-
rubygems_version: 3.
|
183
|
+
rubygems_version: 3.5.9
|
181
184
|
signing_key:
|
182
185
|
specification_version: 4
|
183
186
|
summary: Create system tests interactively.
|
@@ -1,48 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
function ready(fn) {
|
3
|
-
if (document.readyState !== 'loading'){
|
4
|
-
fn();
|
5
|
-
} else {
|
6
|
-
document.addEventListener('DOMContentLoaded', fn);
|
7
|
-
}
|
8
|
-
}
|
9
|
-
|
10
|
-
ready(function() {
|
11
|
-
enableKeyboardShortcuts();
|
12
|
-
});
|
13
|
-
|
14
|
-
|
15
|
-
function enableKeyboardShortcuts() {
|
16
|
-
function keydown(event) {
|
17
|
-
if (event.ctrlKey && event.shiftKey && event.key === 'A') {
|
18
|
-
event.preventDefault();
|
19
|
-
generateAssertion();
|
20
|
-
}
|
21
|
-
}
|
22
|
-
|
23
|
-
document.addEventListener('keydown', keydown, false);
|
24
|
-
|
25
|
-
function generateAssertion() {
|
26
|
-
var text = selectedText().trim();
|
27
|
-
if (text.length > 0) {
|
28
|
-
var action = "assert page.has_content? '" + text.replace("'", "\\\'") + "'";
|
29
|
-
var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
|
30
|
-
var target = "";
|
31
|
-
var options = "";
|
32
|
-
testingOutput.push({action: action, target: target, options: options});
|
33
|
-
sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));
|
34
|
-
alert("Generated an assertion for \"" + selectedText() + "\". Type `flush` in the debugger console to add it to your test file.");
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
function selectedText() {
|
39
|
-
var text = "";
|
40
|
-
if (window.getSelection) {
|
41
|
-
text = window.getSelection().toString();
|
42
|
-
} else if (document.selection && document.selection.type != "Control") {
|
43
|
-
text = document.selection.createRange().text;
|
44
|
-
}
|
45
|
-
return text;
|
46
|
-
}
|
47
|
-
}
|
48
|
-
</script>
|