magic_test 0.0.3 → 0.0.7

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: 055c3c03ddef0cb663a7ed2056b08c550285ff34b467e18225d971fa7f9fc8df
4
- data.tar.gz: dad366cfa42271a6ab70654e10ef33395e5f2e3db6362f802fd811e897a82e19
3
+ metadata.gz: 8157f3ad45a33023af27727450bb43a7a54ef4f390bd21a1d5419f81bfd173d2
4
+ data.tar.gz: 40eab3d8bfe379bc346f294ed3d881521ddf8defcf7d53a1e60c994050a54b5c
5
5
  SHA512:
6
- metadata.gz: d95bf68163b3b91ee927958ba914e380f55e28324ae2546aaa6cd036c1bfe3d0295768f82a4f489ca2c14e8b57749e0292c7481dfdfde2e0e55fbbb835d8ddb5
7
- data.tar.gz: ed563a867e518ceae203881b718d7637a3730d751bda506786e7b4549a95417202ba9d3ed3bf8a7c8472d72207a457017e73a513b478a032cebadb29166a09ea
6
+ metadata.gz: 91e84e80faf56d07bf8df3540c09c8324f12e85fe395bf75876d3316ec76d810f19436ceb1773d7848d52cc039c95e853aeac8222af3c9da1042c5ab50ea6d99
7
+ data.tar.gz: 13fad9265f6b3cf86a2d26760628680dc59c6aeeab896963e18d037effe0c8444e2449a48d2adcabdec937c628d1060ab8328e90565c7c6a772c75395226c106
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ ignore: # default: []
2
+ - 'lib/magic_test/support.rb':
3
+ - Lint/Debugger
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in magic_test.gemspec
6
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,81 +1,83 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- magic_test (0.0.1)
5
- capybara (~> 3.0)
4
+ magic_test (0.0.6)
5
+ capybara (>= 3.0)
6
6
  pry
7
7
  pry-stack_explorer
8
- rails (~> 6.0)
8
+ rails (>= 6.0)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actioncable (6.1.3)
14
- actionpack (= 6.1.3)
15
- activesupport (= 6.1.3)
13
+ actioncable (7.0.0)
14
+ actionpack (= 7.0.0)
15
+ activesupport (= 7.0.0)
16
16
  nio4r (~> 2.0)
17
17
  websocket-driver (>= 0.6.1)
18
- actionmailbox (6.1.3)
19
- actionpack (= 6.1.3)
20
- activejob (= 6.1.3)
21
- activerecord (= 6.1.3)
22
- activestorage (= 6.1.3)
23
- activesupport (= 6.1.3)
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)
24
24
  mail (>= 2.7.1)
25
- actionmailer (6.1.3)
26
- actionpack (= 6.1.3)
27
- actionview (= 6.1.3)
28
- activejob (= 6.1.3)
29
- activesupport (= 6.1.3)
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)
30
30
  mail (~> 2.5, >= 2.5.4)
31
31
  rails-dom-testing (~> 2.0)
32
- actionpack (6.1.3)
33
- actionview (= 6.1.3)
34
- activesupport (= 6.1.3)
35
- rack (~> 2.0, >= 2.0.9)
32
+ actionpack (7.0.0)
33
+ actionview (= 7.0.0)
34
+ activesupport (= 7.0.0)
35
+ rack (~> 2.0, >= 2.2.0)
36
36
  rack-test (>= 0.6.3)
37
37
  rails-dom-testing (~> 2.0)
38
38
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
39
- actiontext (6.1.3)
40
- actionpack (= 6.1.3)
41
- activerecord (= 6.1.3)
42
- activestorage (= 6.1.3)
43
- activesupport (= 6.1.3)
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)
44
+ globalid (>= 0.6.0)
44
45
  nokogiri (>= 1.8.5)
45
- actionview (6.1.3)
46
- activesupport (= 6.1.3)
46
+ actionview (7.0.0)
47
+ activesupport (= 7.0.0)
47
48
  builder (~> 3.1)
48
49
  erubi (~> 1.4)
49
50
  rails-dom-testing (~> 2.0)
50
51
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
51
- activejob (6.1.3)
52
- activesupport (= 6.1.3)
52
+ activejob (7.0.0)
53
+ activesupport (= 7.0.0)
53
54
  globalid (>= 0.3.6)
54
- activemodel (6.1.3)
55
- activesupport (= 6.1.3)
56
- activerecord (6.1.3)
57
- activemodel (= 6.1.3)
58
- activesupport (= 6.1.3)
59
- activestorage (6.1.3)
60
- actionpack (= 6.1.3)
61
- activejob (= 6.1.3)
62
- activerecord (= 6.1.3)
63
- activesupport (= 6.1.3)
64
- marcel (~> 0.3.1)
65
- mimemagic (~> 0.3.2)
66
- activesupport (6.1.3)
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)
65
+ marcel (~> 1.0)
66
+ mini_mime (>= 1.1.0)
67
+ activesupport (7.0.0)
67
68
  concurrent-ruby (~> 1.0, >= 1.0.2)
68
69
  i18n (>= 1.6, < 2)
69
70
  minitest (>= 5.1)
70
71
  tzinfo (~> 2.0)
71
- zeitwerk (~> 2.3)
72
- addressable (2.7.0)
72
+ addressable (2.8.0)
73
73
  public_suffix (>= 2.0.2, < 5.0)
74
+ ast (2.4.2)
74
75
  binding_of_caller (1.0.0)
75
76
  debug_inspector (>= 0.0.1)
76
77
  builder (3.2.4)
77
- capybara (3.35.3)
78
+ capybara (3.36.0)
78
79
  addressable
80
+ matrix
79
81
  mini_mime (>= 0.1.3)
80
82
  nokogiri (~> 1.8)
81
83
  rack (>= 1.6.0)
@@ -83,97 +85,114 @@ GEM
83
85
  regexp_parser (>= 1.5, < 3.0)
84
86
  xpath (~> 3.2)
85
87
  coderay (1.1.3)
86
- concurrent-ruby (1.1.8)
88
+ concurrent-ruby (1.1.9)
87
89
  crass (1.0.6)
88
- debug_inspector (1.0.0)
90
+ debug_inspector (1.1.0)
89
91
  erubi (1.10.0)
90
- globalid (0.4.2)
91
- activesupport (>= 4.2.0)
92
- i18n (1.8.9)
92
+ globalid (1.0.0)
93
+ activesupport (>= 5.0)
94
+ i18n (1.8.11)
93
95
  concurrent-ruby (~> 1.0)
94
- loofah (2.9.0)
96
+ loofah (2.13.0)
95
97
  crass (~> 1.0.2)
96
98
  nokogiri (>= 1.5.9)
97
99
  mail (2.7.1)
98
100
  mini_mime (>= 0.1.1)
99
- marcel (0.3.3)
100
- mimemagic (~> 0.3.2)
101
+ marcel (1.0.2)
102
+ matrix (0.4.2)
101
103
  method_source (1.0.0)
102
- mimemagic (0.3.5)
103
- mini_mime (1.0.2)
104
- mini_portile2 (2.5.0)
105
- minitest (5.14.4)
106
- nio4r (2.5.5)
107
- nokogiri (1.11.1)
108
- mini_portile2 (~> 2.5.0)
104
+ mini_mime (1.1.2)
105
+ mini_portile2 (2.6.1)
106
+ minitest (5.15.0)
107
+ nio4r (2.5.8)
108
+ nokogiri (1.12.5)
109
+ mini_portile2 (~> 2.6.1)
109
110
  racc (~> 1.4)
110
- nokogiri (1.11.1-x86_64-darwin)
111
+ nokogiri (1.12.5-x86_64-darwin)
111
112
  racc (~> 1.4)
112
- pry (0.14.0)
113
+ parallel (1.21.0)
114
+ parser (3.0.3.2)
115
+ ast (~> 2.4.1)
116
+ pry (0.14.1)
113
117
  coderay (~> 1.1)
114
118
  method_source (~> 1.0)
115
119
  pry-stack_explorer (0.6.1)
116
120
  binding_of_caller (~> 1.0)
117
121
  pry (~> 0.13)
118
122
  public_suffix (4.0.6)
119
- racc (1.5.2)
123
+ racc (1.6.0)
120
124
  rack (2.2.3)
121
125
  rack-test (1.1.0)
122
126
  rack (>= 1.0, < 3)
123
- rails (6.1.3)
124
- actioncable (= 6.1.3)
125
- actionmailbox (= 6.1.3)
126
- actionmailer (= 6.1.3)
127
- actionpack (= 6.1.3)
128
- actiontext (= 6.1.3)
129
- actionview (= 6.1.3)
130
- activejob (= 6.1.3)
131
- activemodel (= 6.1.3)
132
- activerecord (= 6.1.3)
133
- activestorage (= 6.1.3)
134
- activesupport (= 6.1.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)
135
139
  bundler (>= 1.15.0)
136
- railties (= 6.1.3)
137
- sprockets-rails (>= 2.0.0)
140
+ railties (= 7.0.0)
138
141
  rails-dom-testing (2.0.3)
139
142
  activesupport (>= 4.2.0)
140
143
  nokogiri (>= 1.6)
141
- rails-html-sanitizer (1.3.0)
144
+ rails-html-sanitizer (1.4.2)
142
145
  loofah (~> 2.3)
143
- railties (6.1.3)
144
- actionpack (= 6.1.3)
145
- activesupport (= 6.1.3)
146
+ railties (7.0.0)
147
+ actionpack (= 7.0.0)
148
+ activesupport (= 7.0.0)
146
149
  method_source
147
- rake (>= 0.8.7)
150
+ rake (>= 12.2)
148
151
  thor (~> 1.0)
149
- rake (13.0.3)
150
- regexp_parser (2.1.1)
151
- sprockets (4.0.2)
152
- concurrent-ruby (~> 1.0)
153
- rack (> 1, < 3)
154
- sprockets-rails (3.2.2)
155
- actionpack (>= 4.0)
156
- activesupport (>= 4.0)
157
- sprockets (>= 3.0.0)
152
+ zeitwerk (~> 2.5)
153
+ rainbow (3.0.0)
154
+ rake (13.0.6)
155
+ regexp_parser (2.2.0)
156
+ rexml (3.2.5)
157
+ rubocop (1.23.0)
158
+ parallel (~> 1.10)
159
+ parser (>= 3.0.0.0)
160
+ rainbow (>= 2.2.2, < 4.0)
161
+ regexp_parser (>= 1.8, < 3.0)
162
+ rexml
163
+ rubocop-ast (>= 1.12.0, < 2.0)
164
+ ruby-progressbar (~> 1.7)
165
+ unicode-display_width (>= 1.4.0, < 3.0)
166
+ rubocop-ast (1.15.0)
167
+ parser (>= 3.0.1.1)
168
+ rubocop-performance (1.12.0)
169
+ rubocop (>= 1.7.0, < 2.0)
170
+ rubocop-ast (>= 0.4.0)
171
+ ruby-progressbar (1.11.0)
172
+ standard (1.5.0)
173
+ rubocop (= 1.23.0)
174
+ rubocop-performance (= 1.12.0)
158
175
  thor (1.1.0)
159
176
  tzinfo (2.0.4)
160
177
  concurrent-ruby (~> 1.0)
161
- websocket-driver (0.7.3)
178
+ unicode-display_width (2.1.0)
179
+ websocket-driver (0.7.5)
162
180
  websocket-extensions (>= 0.1.0)
163
181
  websocket-extensions (0.1.5)
164
182
  xpath (3.2.0)
165
183
  nokogiri (~> 1.8)
166
- zeitwerk (2.4.2)
184
+ zeitwerk (2.5.1)
167
185
 
168
186
  PLATFORMS
169
187
  ruby
170
188
  x86_64-darwin-20
171
189
 
172
190
  DEPENDENCIES
173
- bundler (~> 2.0)
191
+ bundler (>= 2.0)
174
192
  magic_test!
175
- minitest (~> 5.0)
176
- rake (~> 13.0)
193
+ minitest (>= 5.0)
194
+ rake (>= 13.0)
195
+ standard
177
196
 
178
197
  BUNDLED WITH
179
- 2.2.0
198
+ 2.2.22
data/README.md CHANGED
@@ -1,8 +1,20 @@
1
1
  # Magic Test
2
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.
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. You can [see some videos of it in action](https://twitter.com/andrewculver/status/1366062684802846721)!
4
4
 
5
- > Magic Test is still in early development, and that includes the documentation. Any questions you have that aren't already address in the documentation should be [opened as issues](https://github.com/bullet-train-co/magic_test/issues/new) so they can be appropriately addressed in the documentation.
5
+ > Magic Test is still in early development, and that includes the documentation. Any questions you have that aren't already address in the documentation should be [opened as issues](https://github.com/bullet-train-co/magic_test/issues/new) so they can be appropriately addressed in the documentation.
6
+
7
+ Magic Test was created by [Andrew Culver](http://twitter.com/andrewculver) and [Adam Pallozzi](https://twitter.com/adampallozzi).
8
+
9
+ ## Sponsored By
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>
14
+ <br/>
15
+ <br/>
16
+
17
+ > Would you like to support Magic Test development and have your logo featured here? [Reach out!](http://twitter.com/andrewculver)
6
18
 
7
19
  ## Installation
8
20
 
@@ -18,14 +30,12 @@ Then run the following in your shell:
18
30
  bundle install
19
31
  ```
20
32
 
21
- Next, run the install generator. If your application already includes jQuery, you can just run:
33
+ Next, run the install generator:
22
34
 
23
35
  ```
24
36
  rails g magic_test:install
25
37
  ```
26
38
 
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
39
  With this we will:
30
40
 
31
41
  - Create a sample system test at `test/system/basics_test.rb` that invokes Magic Test.
@@ -59,7 +69,7 @@ If you have the screen real estate, we recommend organizing the three windows so
59
69
 
60
70
  ### Writing Tests Manually in the Debugger Console
61
71
 
62
- 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.
72
+ You’re now free to issue Capybara commands in the debugger and see their results in the Chrome browser. If you type something and you’re happy with the result, type `ok` and hit enter to have the last line or block of code you wrote added to the test.
63
73
 
64
74
  When you’re done writing the test interactively, you can press <kbd>Control</kbd> + <kbd>D</kbd> to finish running the test.
65
75
 
@@ -85,6 +95,9 @@ The interactive actions you make in your app are not automatically written to yo
85
95
 
86
96
  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.
87
97
 
98
+ ## Acknowledgements
99
+ We'd like to thank [Florian Plank](https://twitter.com/polarblau), the author of [Capycorder](https://github.com/polarblau/capycorder). His earlier attempt at the same concept (implemented via a Chrome extension) was ahead of its time and provided us with great inspiration and lessons learned when solving this problem from another angle.
100
+
88
101
  ## Contributing
89
102
 
90
103
  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.
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList["test/**/*_test.rb"]
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
@@ -1,10 +1,17 @@
1
1
  <script>
2
+ function ready(fn) {
3
+ if (document.readyState !== 'loading'){
4
+ fn();
5
+ } else {
6
+ document.addEventListener('DOMContentLoaded', fn);
7
+ }
8
+ }
2
9
 
3
- // TODO do we have to do this differently for turbo?
4
- $(document).ready(function() {
10
+ ready(function() {
5
11
  enableKeyboardShortcuts();
6
12
  });
7
13
 
14
+
8
15
  function enableKeyboardShortcuts() {
9
16
  function keydown(event) {
10
17
  if (event.ctrlKey && event.shiftKey && event.key === 'A') {
@@ -16,9 +23,9 @@
16
23
  document.addEventListener('keydown', keydown, false);
17
24
 
18
25
  function generateAssertion() {
19
- var text = selectedText();
20
- if (text.trim().length > 0) {
21
- var action = "assert page.has_content?('" + text.replace("'", "\\\'") + "')";
26
+ var text = selectedText().trim();
27
+ if (text.length > 0) {
28
+ var action = "assert page.has_content? '" + text.replace("'", "\\\'") + "'";
22
29
  var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
23
30
  var target = "";
24
31
  var options = "";
@@ -1,7 +1,7 @@
1
1
  <script>
2
2
 
3
3
  function getPathTo(element) {
4
- if (element.tagName == 'HTML') {
4
+ if (element.tagName === 'HTML') {
5
5
  return '/HTML[1]';
6
6
  }
7
7
  if (element===document.body) {
@@ -20,27 +20,30 @@
20
20
  }
21
21
  }
22
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';
23
+ function visibleFilter(target){
24
+ var computedStyle = window.getComputedStyle(target);
25
+ return !(computedStyle.display === 'none' || computedStyle.visibility === 'hidden' || target.hidden)
26
26
  }
27
27
 
28
28
 
29
29
  function finderForElement(element) {
30
30
  // Try to find just using the element tagName
31
31
  var tagName = element.tagName.toLowerCase();
32
- if ($(tagName).length == 1) {
32
+ if (document.querySelectorAll(tagName).length === 1) {
33
33
  return `find('${tagName}')`;
34
34
  }
35
35
  // Try adding in the classes of the element
36
36
  var classList = [].slice.apply(element.classList)
37
37
  var classString = classList.length ? "." + classList.join('.') : "";
38
- if (classList.length && $(tagName + classList).length == 1) {
38
+ if (classList.length && document.querySelectorAll(tagName + classList).length === 1) {
39
39
  return `find('${tagName}${classString}')`;
40
40
  }
41
41
  // Try adding in the text of the element
42
42
  var text = element.textContent.trim();
43
- if (text && $(tagName + classString + `:contains(${text}):visible`).filter(visibleFilter).length == 1) {
43
+ var targets = Array.from(document.querySelectorAll(`${tagName}${classString}`))
44
+ .filter(visibleFilter)
45
+ .filter((el) => el.textContent.includes(text))
46
+ if (text && targets.length === 1) {
44
47
  return `find('${tagName}${classString}', text: '${text}')`;
45
48
  }
46
49
  // use the xpath to the element
@@ -48,4 +51,4 @@
48
51
  }
49
52
 
50
53
 
51
- </script>
54
+ </script>
@@ -1,29 +1,30 @@
1
1
  <script text="text/javascript">
2
2
 
3
- $(function() {
3
+ ready(function() {
4
4
  console.log("🪄 Magic Test activated in the browser!")
5
5
  initializeStorage();
6
6
  initializeMutationObserver();
7
7
  });
8
8
 
9
9
  function clickFunction(event) {
10
- var tagName = event.currentTarget.tagName
10
+ var element = event.target
11
+ var tagName = element.tagName
11
12
  var action = ""
12
13
  var target = ""
13
14
  var options = ""
14
- if (tagName == "BUTTON" || tagName == "A" || (tagName == "INPUT" && event.currentTarget.type == 'submit')) {
15
+ if (tagName == "BUTTON" || tagName == "A" || (tagName == "INPUT" && element.type == 'submit')) {
15
16
  action = "click_on"
16
- var target = event.currentTarget.value || event.currentTarget.text
17
+ target = element.value || element.text
17
18
  if (!target) {
18
19
  return;
19
20
  }
20
21
  target = "\'" + target.trim().replace("'", "\\\'") + "\'"
21
22
  } else if (tagName == "INPUT") {
22
23
  let ignoreType = ['text', 'password', 'date', 'email', 'month', 'number', 'search']
23
- if (ignoreType.includes(event.currentTarget.type)) {
24
+ if (ignoreType.includes(element.type)) {
24
25
  return;
25
26
  }
26
- var path = getPathTo(event.currentTarget)
27
+ var path = getPathTo(element)
27
28
  action = `find(:xpath, '${path}').click`
28
29
  } else {
29
30
  return;
@@ -4,6 +4,5 @@
4
4
  document.addEventListener('keypress', function(e){keypressFunction(e)});
5
5
  document.addEventListener('mouseover', function(evt){mutationStart(evt)}, true);
6
6
  document.addEventListener('mouseover', function(){mutationEnd()}, false);
7
-
8
- $(document).on('click', '*', function(event){clickFunction(event)});
7
+ document.addEventListener('click', function(event){clickFunction(event)});
9
8
  </script>
@@ -1,8 +1,4 @@
1
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
2
  <%= render 'magic_test/context_menu' %>
7
3
  <%= render 'magic_test/key_codes' %>
8
4
  <%= render 'magic_test/storage' %>
@@ -1,40 +1,28 @@
1
- require 'rails/generators'
2
- require 'magic_test/engine'
1
+ require "rails/generators"
2
+ require "magic_test/engine"
3
3
 
4
4
  module MagicTest
5
5
  class InstallGenerator < Rails::Generators::Base
6
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'
7
+ [MagicTest::Engine.root, File.expand_path("../templates", __FILE__)]
16
8
  end
17
9
 
18
10
  def install
19
11
  unless defined?(MagicTest)
20
12
  gem_group :test do
21
- gem 'magic_test'
13
+ gem "magic_test"
22
14
  end
23
15
  end
24
16
 
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
-
17
+ 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"
37
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)"
38
26
  end
39
27
  end
40
28
  end
@@ -1,9 +1,11 @@
1
- require 'magic_test/support'
1
+ require "magic_test/support"
2
+ require "pry"
3
+ require "pry-stack_explorer"
2
4
 
3
5
  module MagicTest
4
6
  class Engine < Rails::Engine
5
7
  config.after_initialize do
6
- if ENV['MAGIC_TEST'].present?
8
+ if ENV["MAGIC_TEST"].present?
7
9
  if defined? ActionDispatch::SystemTestCase
8
10
  ActionDispatch::SystemTestCase.include MagicTest::Support
9
11
  end
@@ -11,6 +13,12 @@ module MagicTest
11
13
  if defined? ActionDispatch::IntegrationTest
12
14
  ActionDispatch::IntegrationTest.include MagicTest::Support
13
15
  end
16
+
17
+ if defined? RSpec
18
+ RSpec.configure do |config|
19
+ config.include MagicTest::Support, type: :system
20
+ end
21
+ end
14
22
  end
15
23
  end
16
24
  end
@@ -1,7 +1,7 @@
1
1
  module MagicTest
2
2
  class Railtie < Rails::Railtie
3
3
  rake_tasks do
4
- Dir[File.join(File.dirname(__FILE__),'../tasks/*.rake')].each { |f| load f }
4
+ Dir[File.join(File.dirname(__FILE__), "../tasks/*.rake")].each { |f| load f }
5
5
  end
6
6
  end
7
7
  end
@@ -3,14 +3,16 @@ module MagicTest
3
3
  def assert_selected_exists
4
4
  selected_text = page.evaluate_script("window.selectedText()")
5
5
  return if selected_text.blank?
6
- filepath, line = caller.select { |s| s.include?("/test/") }.reject { |s| s.include?("helper") }.first.split(':')
6
+
7
+ filepath, line = get_last_caller(caller)
8
+
7
9
  contents = File.open(filepath).read.lines
8
10
  chunks = contents.each_slice(line.to_i - 1 + @test_lines_written).to_a
9
11
  indentation = chunks[1].first.match(/^(\s*)/)[0]
10
12
  chunks.first << indentation + "assert(page.has_content?('#{selected_text.gsub("'", "\\\\'")}'))" + "\n"
11
13
  @test_lines_written += 1
12
14
  contents = chunks.flatten.join
13
- File.open(filepath, 'w') do |file|
15
+ File.open(filepath, "w") do |file|
14
16
  file.puts(contents)
15
17
  end
16
18
  end
@@ -19,24 +21,9 @@ module MagicTest
19
21
  page.evaluate_script("trackKeystrokes()")
20
22
  end
21
23
 
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
24
  def flush
39
- filepath, line = caller.select { |s| s.include?("/test/") }.reject { |s| s.include?("helper") }.first.split(':')
25
+ filepath, line = get_last_caller(caller)
26
+
40
27
  contents = File.open(filepath).read.lines
41
28
  chunks = contents.each_slice(line.to_i - 1 + @test_lines_written).to_a
42
29
  indentation = chunks[1].first.match(/^(\s*)/)[0]
@@ -48,11 +35,11 @@ module MagicTest
48
35
  puts "(writing that to `#{filepath}`.)"
49
36
  if output
50
37
  output.each do |last|
51
- chunks.first << indentation + "#{last['action']} #{last['target']}#{last['options']}" + "\n"
38
+ chunks.first << indentation + "#{last["action"]} #{last["target"]}#{last["options"]}" + "\n"
52
39
  @test_lines_written += 1
53
40
  end
54
41
  contents = chunks.flatten.join
55
- File.open(filepath, 'w') do |file|
42
+ File.open(filepath, "w") do |file|
56
43
  file.puts(contents)
57
44
  end
58
45
  # clear the testing output now.
@@ -60,11 +47,12 @@ module MagicTest
60
47
  else
61
48
  puts "`window.testingOutput` was empty in the browser. Something must be wrong on the browser side."
62
49
  end
63
- return true
50
+ true
64
51
  end
65
52
 
66
53
  def ok
67
- filepath, line = caller.select { |s| s.include?("/test/") }.reject { |s| s.include?("helper") }.first.split(':')
54
+ filepath, line = get_last_caller(caller)
55
+
68
56
  puts "(writing that to `#{filepath}`.)"
69
57
  contents = File.open(filepath).read.lines
70
58
  chunks = contents.each_slice(line.to_i - 1 + @test_lines_written).to_a
@@ -74,14 +62,17 @@ module MagicTest
74
62
  @test_lines_written += 1
75
63
  end
76
64
  contents = chunks.flatten.join
77
- File.open(filepath, 'w') do |file|
65
+ File.open(filepath, "w") do |file|
78
66
  file.puts(contents)
79
67
  end
80
- return true
68
+ true
81
69
  end
82
70
 
83
71
  def empty_cache
84
72
  page.evaluate_script("sessionStorage.setItem('testingOutput', JSON.stringify([]))")
73
+ rescue Capybara::NotSupportedByDriverError => _
74
+ # TODO we need to add more robust instructions for this.
75
+ raise "You need to configure this test (or your test suite) to run in a real browser (Chrome, Firefox, etc.) in order for Magic Test to work. It also needs to run in non-headless mode if `ENV['MAGIC_TEST'].present?`"
85
76
  end
86
77
 
87
78
  def magic_test
@@ -94,5 +85,31 @@ module MagicTest
94
85
  retry
95
86
  end
96
87
  end
88
+
89
+ private
90
+
91
+ def get_last
92
+ history_lines = Readline::HISTORY.to_a.last(20)
93
+ i = 2
94
+ last = history_lines.last(2).first
95
+ last_block = [last]
96
+ if last == "end" || last.first(4) == "end "
97
+ i += 1
98
+ last_block.unshift(history_lines.last(i).first)
99
+ until !last_block.first.match(/^(\s+)/) & [0]
100
+ i += 1
101
+ last_block.unshift(history_lines.last(i).first)
102
+ end
103
+ end
104
+
105
+ last_block
106
+ end
107
+
108
+ # TODO this feels like it's going to end up burning people who have other support files in `test` or `spec` that don't include `helper` in the name.
109
+ def get_last_caller(caller)
110
+ caller.select { |s| s.include?("/test/") || s.include?("/spec/") }
111
+ .reject { |s| s.include?("helper") }
112
+ .first.split(":").first(2)
113
+ end
97
114
  end
98
115
  end
@@ -1,3 +1,3 @@
1
1
  module MagicTest
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/magic_test.rb CHANGED
@@ -6,9 +6,6 @@ require "magic_test/support"
6
6
  module MagicTest
7
7
  class Error < StandardError; end
8
8
 
9
- mattr_accessor :jquery_already_included
10
- @@jquery_already_included = false
11
-
12
9
  def self.setup
13
10
  yield self
14
11
  end
@@ -1,6 +1,6 @@
1
1
  namespace :magic_test do
2
2
  desc "Install Magic Test"
3
3
  task :install do
4
- system 'rails g magic_test:install'
4
+ system "rails g magic_test:install"
5
5
  end
6
6
  end
data/magic_test.gemspec CHANGED
@@ -3,30 +3,31 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require "magic_test/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "magic_test"
7
- spec.version = MagicTest::VERSION
8
- spec.authors = ["Andrew Culver", "Adam Pallozzi"]
9
- spec.email = ["andrew.culver@gmail.com", "adampallozzi@gmail.com"]
6
+ spec.name = "magic_test"
7
+ spec.version = MagicTest::VERSION
8
+ spec.authors = ["Andrew Culver", "Adam Pallozzi"]
9
+ spec.email = ["andrew.culver@gmail.com", "adampallozzi@gmail.com"]
10
10
 
11
- spec.summary = %q{Create system tests interactively.}
12
- spec.homepage = "https://github.com/bullet-train/magic_test"
13
- spec.license = "MIT"
11
+ spec.summary = "Create system tests interactively."
12
+ spec.homepage = "https://github.com/bullet-train/magic_test"
13
+ spec.license = "MIT"
14
14
 
15
15
  # Specify which files should be added to the gem when it is released.
16
16
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
18
18
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
19
  end
20
- spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_development_dependency "bundler", "~> 2.0"
25
- spec.add_development_dependency "rake", "~> 13.0"
26
- spec.add_development_dependency "minitest", "~> 5.0"
24
+ spec.add_development_dependency "bundler", ">= 2.0"
25
+ spec.add_development_dependency "rake", ">= 13.0"
26
+ spec.add_development_dependency "minitest", ">= 5.0"
27
+ spec.add_development_dependency "standard"
27
28
 
28
29
  spec.add_dependency "pry"
29
30
  spec.add_dependency "pry-stack_explorer"
30
- spec.add_dependency "capybara", "~> 3.0"
31
- spec.add_dependency "rails", "~> 6.0"
31
+ spec.add_dependency "capybara", ">= 3.0"
32
+ spec.add_dependency "rails", ">= 6.0"
32
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.3
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Culver
@@ -9,50 +9,64 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-02-28 00:00:00.000000000 Z
12
+ date: 2021-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '2.0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '2.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '13.0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '13.0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: minitest
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '5.0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '5.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: standard
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: pry
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -85,28 +99,28 @@ dependencies:
85
99
  name: capybara
86
100
  requirement: !ruby/object:Gem::Requirement
87
101
  requirements:
88
- - - "~>"
102
+ - - ">="
89
103
  - !ruby/object:Gem::Version
90
104
  version: '3.0'
91
105
  type: :runtime
92
106
  prerelease: false
93
107
  version_requirements: !ruby/object:Gem::Requirement
94
108
  requirements:
95
- - - "~>"
109
+ - - ">="
96
110
  - !ruby/object:Gem::Version
97
111
  version: '3.0'
98
112
  - !ruby/object:Gem::Dependency
99
113
  name: rails
100
114
  requirement: !ruby/object:Gem::Requirement
101
115
  requirements:
102
- - - "~>"
116
+ - - ">="
103
117
  - !ruby/object:Gem::Version
104
118
  version: '6.0'
105
119
  type: :runtime
106
120
  prerelease: false
107
121
  version_requirements: !ruby/object:Gem::Requirement
108
122
  requirements:
109
- - - "~>"
123
+ - - ">="
110
124
  - !ruby/object:Gem::Version
111
125
  version: '6.0'
112
126
  description:
@@ -118,6 +132,7 @@ extensions: []
118
132
  extra_rdoc_files: []
119
133
  files:
120
134
  - ".gitignore"
135
+ - ".standard.yml"
121
136
  - ".travis.yml"
122
137
  - CODE_OF_CONDUCT.md
123
138
  - Gemfile
@@ -136,7 +151,6 @@ files:
136
151
  - bin/console
137
152
  - bin/setup
138
153
  - lib/generators/magic_test/install_generator.rb
139
- - lib/generators/magic_test/templates/config/initializers/magic_test.rb
140
154
  - lib/magic_test.rb
141
155
  - lib/magic_test/engine.rb
142
156
  - lib/magic_test/railtie.rb
@@ -163,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
177
  - !ruby/object:Gem::Version
164
178
  version: '0'
165
179
  requirements: []
166
- rubygems_version: 3.1.4
180
+ rubygems_version: 3.2.22
167
181
  signing_key:
168
182
  specification_version: 4
169
183
  summary: Create system tests interactively.
@@ -1,3 +0,0 @@
1
- MagicTest.setup do |config|
2
- config.jquery_already_included = <%= jquery_already_included ? 'true' : 'false' %>
3
- end if Rails.env.test?