magic_test 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8157f3ad45a33023af27727450bb43a7a54ef4f390bd21a1d5419f81bfd173d2
4
- data.tar.gz: 40eab3d8bfe379bc346f294ed3d881521ddf8defcf7d53a1e60c994050a54b5c
3
+ metadata.gz: 015de5e14bc97d6b2c2b878fbac4a9e77bce655e1d76c34ef5c8c8f294d4ebfe
4
+ data.tar.gz: 9e4097db71f6a09517a78a68da450606c4a06413da6ddeef2ca921f9c4009be8
5
5
  SHA512:
6
- metadata.gz: 91e84e80faf56d07bf8df3540c09c8324f12e85fe395bf75876d3316ec76d810f19436ceb1773d7848d52cc039c95e853aeac8222af3c9da1042c5ab50ea6d99
7
- data.tar.gz: 13fad9265f6b3cf86a2d26760628680dc59c6aeeab896963e18d037effe0c8444e2449a48d2adcabdec937c628d1060ab8328e90565c7c6a772c75395226c106
6
+ metadata.gz: ac6f104c5be822130351be8222231a85ba0512c7a9db07e00938942341df7fc18a12e0f764fc1f81a0e3c83fc251d3d2f3f0f021ae7dd3fa6d7b1359ae488759
7
+ data.tar.gz: 0647614ed4b0a9ed3882dafeadf668c0b27b7d185eff280079b7bd6dc3512183e68f5c6f3720f7cf6d6a509dae5d631a2ee247e9d9e985da66c20c66e9d3d233
data/.gitignore CHANGED
@@ -3,6 +3,12 @@
3
3
  /_yardoc/
4
4
  /coverage/
5
5
  /doc/
6
+ /log/*.log
6
7
  /pkg/
7
8
  /spec/reports/
8
9
  /tmp/
10
+ /test/dummy/db/*.sqlite3
11
+ /test/dummy/db/*.sqlite3-*
12
+ /test/dummy/log/*.log
13
+ /test/dummy/storage/
14
+ /test/dummy/tmp/
data/Gemfile CHANGED
@@ -2,5 +2,8 @@ source "https://rubygems.org"
2
2
 
3
3
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
+ gem "sqlite3"
6
+ gem "sprockets-rails"
7
+
5
8
  # Specify your gem's dependencies in magic_test.gemspec
6
9
  gemspec
data/Gemfile.lock CHANGED
@@ -1,81 +1,87 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- magic_test (0.0.6)
4
+ magic_test (0.1.0)
5
5
  capybara (>= 3.0)
6
6
  pry
7
7
  pry-stack_explorer
8
- rails (>= 6.0)
8
+ rails (>= 5.0)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actioncable (7.0.0)
14
- actionpack (= 7.0.0)
15
- activesupport (= 7.0.0)
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.0)
19
- actionpack (= 7.0.0)
20
- activejob (= 7.0.0)
21
- activerecord (= 7.0.0)
22
- activestorage (= 7.0.0)
23
- activesupport (= 7.0.0)
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
- actionmailer (7.0.0)
26
- actionpack (= 7.0.0)
27
- actionview (= 7.0.0)
28
- activejob (= 7.0.0)
29
- activesupport (= 7.0.0)
25
+ net-imap
26
+ net-pop
27
+ net-smtp
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)
30
33
  mail (~> 2.5, >= 2.5.4)
34
+ net-imap
35
+ net-pop
36
+ net-smtp
31
37
  rails-dom-testing (~> 2.0)
32
- actionpack (7.0.0)
33
- actionview (= 7.0.0)
34
- activesupport (= 7.0.0)
38
+ actionpack (7.0.2.3)
39
+ actionview (= 7.0.2.3)
40
+ activesupport (= 7.0.2.3)
35
41
  rack (~> 2.0, >= 2.2.0)
36
42
  rack-test (>= 0.6.3)
37
43
  rails-dom-testing (~> 2.0)
38
44
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
39
- actiontext (7.0.0)
40
- actionpack (= 7.0.0)
41
- activerecord (= 7.0.0)
42
- activestorage (= 7.0.0)
43
- activesupport (= 7.0.0)
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)
44
50
  globalid (>= 0.6.0)
45
51
  nokogiri (>= 1.8.5)
46
- actionview (7.0.0)
47
- activesupport (= 7.0.0)
52
+ actionview (7.0.2.3)
53
+ activesupport (= 7.0.2.3)
48
54
  builder (~> 3.1)
49
55
  erubi (~> 1.4)
50
56
  rails-dom-testing (~> 2.0)
51
57
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
52
- activejob (7.0.0)
53
- activesupport (= 7.0.0)
58
+ activejob (7.0.2.3)
59
+ activesupport (= 7.0.2.3)
54
60
  globalid (>= 0.3.6)
55
- activemodel (7.0.0)
56
- activesupport (= 7.0.0)
57
- activerecord (7.0.0)
58
- activemodel (= 7.0.0)
59
- activesupport (= 7.0.0)
60
- activestorage (7.0.0)
61
- actionpack (= 7.0.0)
62
- activejob (= 7.0.0)
63
- activerecord (= 7.0.0)
64
- activesupport (= 7.0.0)
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)
65
71
  marcel (~> 1.0)
66
72
  mini_mime (>= 1.1.0)
67
- activesupport (7.0.0)
73
+ activesupport (7.0.2.3)
68
74
  concurrent-ruby (~> 1.0, >= 1.0.2)
69
75
  i18n (>= 1.6, < 2)
70
76
  minitest (>= 5.1)
71
77
  tzinfo (~> 2.0)
72
- addressable (2.8.0)
73
- public_suffix (>= 2.0.2, < 5.0)
78
+ addressable (2.8.1)
79
+ public_suffix (>= 2.0.2, < 6.0)
74
80
  ast (2.4.2)
75
81
  binding_of_caller (1.0.0)
76
82
  debug_inspector (>= 0.0.1)
77
83
  builder (3.2.4)
78
- capybara (3.36.0)
84
+ capybara (3.38.0)
79
85
  addressable
80
86
  matrix
81
87
  mini_mime (>= 0.1.3)
@@ -87,28 +93,39 @@ GEM
87
93
  coderay (1.1.3)
88
94
  concurrent-ruby (1.1.9)
89
95
  crass (1.0.6)
96
+ date (3.3.2)
90
97
  debug_inspector (1.1.0)
91
98
  erubi (1.10.0)
92
99
  globalid (1.0.0)
93
100
  activesupport (>= 5.0)
94
- i18n (1.8.11)
101
+ i18n (1.10.0)
95
102
  concurrent-ruby (~> 1.0)
96
- loofah (2.13.0)
103
+ loofah (2.14.0)
97
104
  crass (~> 1.0.2)
98
105
  nokogiri (>= 1.5.9)
99
- mail (2.7.1)
106
+ mail (2.8.0)
100
107
  mini_mime (>= 0.1.1)
108
+ net-imap
109
+ net-pop
110
+ net-smtp
101
111
  marcel (1.0.2)
102
112
  matrix (0.4.2)
103
113
  method_source (1.0.0)
104
114
  mini_mime (1.1.2)
105
- mini_portile2 (2.6.1)
115
+ mini_portile2 (2.8.0)
106
116
  minitest (5.15.0)
107
- nio4r (2.5.8)
108
- nokogiri (1.12.5)
109
- mini_portile2 (~> 2.6.1)
110
- racc (~> 1.4)
111
- nokogiri (1.12.5-x86_64-darwin)
117
+ net-imap (0.3.2)
118
+ date
119
+ net-protocol
120
+ net-pop (0.1.2)
121
+ net-protocol
122
+ net-protocol (0.2.1)
123
+ timeout
124
+ net-smtp (0.3.3)
125
+ net-protocol
126
+ nio4r (2.5.9)
127
+ nokogiri (1.13.3)
128
+ mini_portile2 (~> 2.8.0)
112
129
  racc (~> 1.4)
113
130
  parallel (1.21.0)
114
131
  parser (3.0.3.2)
@@ -119,33 +136,33 @@ GEM
119
136
  pry-stack_explorer (0.6.1)
120
137
  binding_of_caller (~> 1.0)
121
138
  pry (~> 0.13)
122
- public_suffix (4.0.6)
139
+ public_suffix (5.0.1)
123
140
  racc (1.6.0)
124
141
  rack (2.2.3)
125
142
  rack-test (1.1.0)
126
143
  rack (>= 1.0, < 3)
127
- rails (7.0.0)
128
- actioncable (= 7.0.0)
129
- actionmailbox (= 7.0.0)
130
- actionmailer (= 7.0.0)
131
- actionpack (= 7.0.0)
132
- actiontext (= 7.0.0)
133
- actionview (= 7.0.0)
134
- activejob (= 7.0.0)
135
- activemodel (= 7.0.0)
136
- activerecord (= 7.0.0)
137
- activestorage (= 7.0.0)
138
- activesupport (= 7.0.0)
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)
139
156
  bundler (>= 1.15.0)
140
- railties (= 7.0.0)
157
+ railties (= 7.0.2.3)
141
158
  rails-dom-testing (2.0.3)
142
159
  activesupport (>= 4.2.0)
143
160
  nokogiri (>= 1.6)
144
161
  rails-html-sanitizer (1.4.2)
145
162
  loofah (~> 2.3)
146
- railties (7.0.0)
147
- actionpack (= 7.0.0)
148
- activesupport (= 7.0.0)
163
+ railties (7.0.2.3)
164
+ actionpack (= 7.0.2.3)
165
+ activesupport (= 7.0.2.3)
149
166
  method_source
150
167
  rake (>= 12.2)
151
168
  thor (~> 1.0)
@@ -169,10 +186,20 @@ GEM
169
186
  rubocop (>= 1.7.0, < 2.0)
170
187
  rubocop-ast (>= 0.4.0)
171
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)
172
198
  standard (1.5.0)
173
199
  rubocop (= 1.23.0)
174
200
  rubocop-performance (= 1.12.0)
175
- thor (1.1.0)
201
+ thor (1.2.1)
202
+ timeout (0.3.1)
176
203
  tzinfo (2.0.4)
177
204
  concurrent-ruby (~> 1.0)
178
205
  unicode-display_width (2.1.0)
@@ -181,7 +208,7 @@ GEM
181
208
  websocket-extensions (0.1.5)
182
209
  xpath (3.2.0)
183
210
  nokogiri (~> 1.8)
184
- zeitwerk (2.5.1)
211
+ zeitwerk (2.6.6)
185
212
 
186
213
  PLATFORMS
187
214
  ruby
@@ -192,7 +219,9 @@ DEPENDENCIES
192
219
  magic_test!
193
220
  minitest (>= 5.0)
194
221
  rake (>= 13.0)
222
+ sprockets-rails
223
+ sqlite3
195
224
  standard
196
225
 
197
226
  BUNDLED WITH
198
- 2.2.22
227
+ 2.5.10
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 Andrew Culver
3
+ Copyright (c) 2020 Bullet Train, Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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
- - Create a sample system test at `test/system/basics_test.rb` that invokes Magic Test.
42
- - 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.
43
-
44
- 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`:
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 `MAGIC_TEST=1 rails test:system test/system/basics_test.rb` on the shell.
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: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.
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
- 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.
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
- gsub_file "test/system/basics_test.rb", "# ", ""
19
- gsub_file "test/system/basics_test.rb", "#", ""
20
- gsub_file "test/system/basics_test.rb", "visiting the index", "getting started"
21
- gsub_file "test/system/basics_test.rb", "visit basics_url", "visit root_url"
22
- gsub_file "test/system/basics_test.rb", 'assert_selector "h1", text: "Basic"', "magic_test"
23
-
24
- gsub_file "test/application_system_test_case.rb", "using: :headless_chrome", "using: (ENV['SHOW_TESTS'] ? :chrome : :headless_chrome)"
25
- gsub_file "test/application_system_test_case.rb", "using: :headless_firefox", "using: (ENV['SHOW_TESTS'] ? :firefox : :headless_firefox)"
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
@@ -76,10 +76,11 @@ module MagicTest
76
76
  end
77
77
 
78
78
  def magic_test
79
+ return unless ENV["MAGIC_TEST"].present?
79
80
  empty_cache
80
81
  @test_lines_written = 0
81
82
  begin
82
- # 👋 This isn't helpful context. Type `up` and hit enter to see where you really are.
83
+ magic_test_pry_hook
83
84
  binding.pry
84
85
  rescue
85
86
  retry
@@ -88,6 +89,17 @@ module MagicTest
88
89
 
89
90
  private
90
91
 
92
+ def magic_test_pry_hook
93
+ Pry.hooks.add_hook(:before_session, "magic_test") do |output, binding, pry|
94
+ Pry.hooks.delete_hook(:before_session, 'magic_test')
95
+ magic_test_file_index = pry.backtrace.index{|line| line.include?(__FILE__)}
96
+ # walk up backtrace until finding the original caller
97
+ until pry.backtrace[magic_test_file_index + 1].include?(pry.last_file) do
98
+ pry.run_command('up')
99
+ end
100
+ end
101
+ end
102
+
91
103
  def get_last
92
104
  history_lines = Readline::HISTORY.to_a.last(20)
93
105
  i = 2
@@ -1,3 +1,3 @@
1
1
  module MagicTest
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.0"
3
3
  end
data/magic_test.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["andrew.culver@gmail.com", "adampallozzi@gmail.com"]
10
10
 
11
11
  spec.summary = "Create system tests interactively."
12
- spec.homepage = "https://github.com/bullet-train/magic_test"
12
+ spec.homepage = "https://github.com/bullet-train-co/magic_test"
13
13
  spec.license = "MIT"
14
14
 
15
15
  # Specify which files should be added to the gem when it is released.
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "pry"
30
30
  spec.add_dependency "pry-stack_explorer"
31
31
  spec.add_dependency "capybara", ">= 3.0"
32
- spec.add_dependency "rails", ">= 6.0"
32
+ spec.add_dependency "rails", ">= 5.0"
33
33
  end
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.7
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: 2021-12-16 00:00:00.000000000 Z
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: '6.0'
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: '6.0'
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
@@ -158,7 +161,7 @@ files:
158
161
  - lib/magic_test/version.rb
159
162
  - lib/tasks/magic_test.rake
160
163
  - magic_test.gemspec
161
- homepage: https://github.com/bullet-train/magic_test
164
+ homepage: https://github.com/bullet-train-co/magic_test
162
165
  licenses:
163
166
  - MIT
164
167
  metadata: {}
@@ -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.2.22
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>