You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
+`bundle exec foreman start` to start Rails and the Hotloader
45
53
+ Navigate to `http://localhost:5000/`
46
54
47
-
> Note that the generator will add a wild card route to the beginning of your routes file. This will let you immediately test Hyperstack, but will also mean that all of your existing routes are now unreachable. So after getting Hyperstack up, you will want to adjust things to your needs. See that last steps in the detailed installation for more info.
55
+
> Note that the generator will add a wild card route to the beginning of your routes file. This will let you immediately test Hyperstack, but will also mean that all of your existing routes are now unreachable. So after getting Hyperstack up, you will want to adjust things to your needs. See that last steps in the **Manual Installation** section for more info.
48
56
49
57
## Manual Installation
50
58
@@ -96,8 +104,6 @@ documented uniform interface to the DOM. To use it require it and its Rails
96
104
counter part in `application.js` before the `hyperstack-loader`
Copy file name to clipboardExpand all lines: docs/tools/hyper-spec.md
+94-58Lines changed: 94 additions & 58 deletions
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,14 @@
1
1
# HyperSpec
2
2
3
-
**Work in progress - ALPHA (docs and code)**
4
-
5
-
With HyperSpec you can run *isomorphic* specs for all your Hyperloop code using RSpec. Everything runs as standard RSpec test specs.
3
+
With HyperSpec you can run *isomorphic* specs for all your Hyperstack code using RSpec. Everything runs as standard RSpec test specs.
6
4
7
5
For example if you have a component like this:
8
6
9
7
```ruby
10
-
classSayHello < React::Component::Base
8
+
classSayHello < HyperComponent
11
9
param :name
12
10
render(DIV) do
13
-
"Hello there #{params.name}"
11
+
"Hello there #{name}"
14
12
end
15
13
end
16
14
```
@@ -30,13 +28,13 @@ The `mount` method will setup a blank client window, and *mount* the named compo
30
28
31
29
Notice that the spec will need a client environment so we must set `js: true`.
32
30
33
-
The `mount` method can also take a block which will be recompiled and set to the client before mounting the component. You can place any client side code in the mount block including the definition of components.
31
+
The `mount` method can also take a block which will be recompiled and sent to the client before mounting the component. You can place any client side code in the mount block including the definition of components.
34
32
35
33
```ruby
36
34
describe "the mount's code block", js:truedo
37
35
it 'will be recompiled on the client'do
38
36
mount 'ShowOff'do
39
-
classShowOff < React::Component::Base
37
+
classShowOff < HyperComponent
40
38
render(DIV) { 'Now how cool is that???' }
41
39
end
42
40
end
@@ -47,39 +45,106 @@ end
47
45
48
46
## Why?
49
47
50
-
Hyperloop wants to make the server-client divide as transparent to the developer as practical. Given this, it makes sense that the testing should also be done with as little concern for client versus server.
51
-
52
-
HyperSpec allows you to directly use tools like FactoryBot (or Hyperloop Operations) to setup some test data, then run a spec to make sure that a component correctly displays, or modifies that data. You can use Timecop to manipulate time and keep in sync between the server and client. This makes testing easier and more realistic without writing a lot of redundant code.
48
+
Hyperstack wants to make the server-client divide as transparent to the developer as practical. Given this, it makes sense that the testing should also be done with as little concern for client versus server.
53
49
50
+
HyperSpec allows you to directly use tools like FactoryBot (or Hyperstack Operations) to setup some test data, then run a spec to make sure that a component correctly displays, or modifies that data. You can use Timecop to manipulate time and keep in sync between the server and client. This makes testing easier and more realistic without writing a lot of redundant code.
54
51
55
52
## Installation
56
53
57
-
Add this line to your application's Gemfile in the test section:
54
+
These instructions are assuming you are using Rails as the backend. However the `hyper-spec` gem itself does not require Rails, so you can adapt these instructions as needed.
# Prevent database truncation if the environment is production
83
+
abort("The Rails environment is running in production mode!") ifRails.env.production?
84
+
require'rspec/rails'
85
+
# Add additional requires below this line. Rails is not loaded until this point!
86
+
87
+
# THESE ARE LINES WE ARE ADDING
88
+
# JUST MAKE SURE THEY ARE AFTER `require 'rspec/rails'`
89
+
90
+
# pull in the hyper-spec code.
70
91
require'hyper-spec'
92
+
93
+
# If you are using DatabaseCleaner here is where
94
+
# you set the mode. We recommend truncation.
95
+
DatabaseCleaner.strategy =:truncation
96
+
97
+
# Now we setup Rspec details
98
+
RSpec.configure do |config|
99
+
100
+
# This is only needed if you are using DatabaseCleaner
101
+
config.before(:each) do
102
+
DatabaseCleaner.clean
103
+
end
104
+
105
+
# If you are NOT using webpacker remove this block
106
+
config.before(:suite) do# compile front-end
107
+
Webpacker.compile
108
+
end
109
+
end
110
+
...
71
111
```
112
+
### Create an install smoke test
72
113
73
-
You will also need to install selenium, poltergeist and firefox version **46.0.1** (ff latest still does not play well with selenium).
114
+
Make sure your installation is working by creating a simple smoke test like this:
115
+
```ruby
116
+
# spec/hyperspec_smoke_test.rb
117
+
require'rails_helper'
118
+
119
+
describe 'Hyperspec', js:truedo
120
+
it 'can mount and test a component'do
121
+
mount "HyperSpecTest"do
122
+
classHyperSpecTest < HyperComponent
123
+
render(DIV) do
124
+
"It's Alive!"
125
+
end
126
+
end
127
+
end
128
+
expect(page).to have_content("It's Alive!")
129
+
end
130
+
it 'can evaluate and test expressions on the client'do
131
+
expect_evaluate_ruby do
132
+
[1, 2, 3].reverse
133
+
end.to eq [3, 2, 1]
134
+
end
135
+
end
136
+
```
137
+
To run it do a
138
+
`bundle exec rspec spec/hyperspec_smoke_test.rb`
74
139
75
-
Sadly at this time the selenium chrome driver does not play nicely with Opal, so you can't use Chrome. We are working on getting rid of the whole selenium business. Stay tuned.
140
+
> Note that because the test does not end in `_spec.rb` it will not be run with the rest of your specs.
76
141
77
142
## Environment Variables
78
143
79
-
You can set `DRIVER` to `ff` to run the client in Firefox and see what is going on. By default tests will run in poltergeist which is quicker, but harder to debug problems.
144
+
You can set `DRIVER` to `chrome` to run the client in chrome and see what is going on. By default tests will run in chrome headless mode which is quicker, but harder to debug problems.
80
145
81
146
```
82
-
DRIVER=ff bundle exec rspec
147
+
DRIVER=chrome bundle exec rspec
83
148
```
84
149
85
150
## Spec Helpers
@@ -109,9 +174,9 @@ mounted may be actually defined in the block, which is useful for setting up top
109
174
110
175
```ruby
111
176
mount 'Display', test:123do
112
-
classDisplay < React::Component::Base
177
+
classDisplay < HyperComponent
113
178
param :test
114
-
render(DIV) { params.test.to_s }
179
+
render(DIV) { test.to_s }
115
180
end
116
181
end
117
182
```
@@ -222,12 +287,12 @@ HyperReact components can *generate* events and perform callbacks. HyperSpec pr
Note that for things to work, the param must be declared as a `type: Proc`.
244
-
245
308
+`callback_history_for`: the entire history given as an array of arrays
246
309
+`last_callback_for`: same as `callback_history_for(xxx).last`
247
310
+`clear_callback_history_for`: clears the array (userful for repeating test variations without remounting)
248
311
+`event_history_for, last_event_for, clear_event_history_for`: same but for events.
249
312
250
313
#### The `pause` Method
251
314
252
-
For debugging. Everything stops, until you type `go()` in the client console. Running binding.pry also has this effect, and is often sufficient, however it will also block the server from responding unless you have a multithreaded server.
315
+
For debugging. Everything stops, until you type `go()` in the client console. Running `binding.pry` also has this effect, and is often sufficient, however it will also block the server from responding unless you have a multithreaded server.
253
316
254
317
#### The `attributes_on_client` Method
255
318
@@ -263,7 +326,7 @@ In other words the method `attributes_on_client` is added to all ActiveRecord mo
Note that after persisting a record the client and server will be synced so this is mainly useful for debug or in rare cases where it is important to interrogate the value on the client before its persisted.
329
+
> Note that after persisting a record the client and server will be synced so this is mainly useful for debug or in rare cases where it is important to interrogate the value on the client before its persisted.
267
330
268
331
#### The `size_window` Method
269
332
@@ -300,7 +363,7 @@ The `add_class` method takes a class name (as a symbol or string), and hash repr
300
363
it "can add classes during testing"do
301
364
add_class :some_class, borderStyle::solid
302
365
mount 'StyledDiv'do
303
-
classStyledDiv < React::Component::Base
366
+
classStyledDiv < HyperComponent
304
367
render(DIV, id:'hello', class: 'some_class') do
305
368
'Hello!'
306
369
end
@@ -318,7 +381,7 @@ The rspec-steps gem will run each test without reloading the window, which is us
318
381
319
382
Checkout the rspec-steps example in the `hyper_spec.rb` file for an example.
320
383
321
-
*Note that hopefully in the near future we are going to build a custom capybara driver that will just directly talk to Hyperloop on the client side. Once this is in place these troubles should go away! - Volunteers welcome to help!*
384
+
> Note that hopefully in the near future we are going to build a custom capybara driver that will just directly talk to Hyperstack on the client side. Once this is in place these troubles should go away! - Volunteers welcome to help!*
322
385
323
386
## Timecop Integration
324
387
@@ -350,31 +413,4 @@ end
350
413
351
414
See the Timecop [README](https://github.com/travisjeffery/timecop/blob/master/README.markdown) for more details.
352
415
353
-
There is one confusing thing to note: On the server if you `sleep` then you will sleep for the specified number of seconds when viewed *outside* of the test. However inside the test environment if you look at Time.now, you will see it advancing according to the scale factor. Likewise if you have a `after` or `every` block on the client, you will wait according to *simulated* time.
354
-
355
-
## Common Problems
356
-
357
-
If you are getting failures on Poltergeist but not Firefox, make sure you are not requiring `browser` in your components.rb.
358
-
Requiring `browser/interval` or `browser/delay` is okay.
359
-
360
-
## Development
361
-
362
-
After checking out the repo, run bundle install and you should be good to go.
363
-
364
-
Tests are run either by running `rake` or for more control:
365
-
366
-
```
367
-
DRIVER=ff bundle exec rspec spec/hyper_spec.rb
368
-
```
369
-
370
-
where DRIVER can be either `ff` (firefox) or `pg` (poltergeist - default).
371
-
372
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
373
-
374
-
## Contributing
375
-
376
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hyper-spec. 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.
377
-
378
-
## License
379
-
380
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
416
+
> There is one confusing thing to note: On the server if you `sleep` then you will sleep for the specified number of seconds when viewed *outside* of the test. However inside the test environment if you look at Time.now, you will see it advancing according to the scale factor. Likewise if you have a `after` or `every` block on the client, you will wait according to *simulated* time.
0 commit comments