Skip to content

Commit fcc8e35

Browse files
committed
closes #396
1 parent 9194ede commit fcc8e35

File tree

6 files changed

+99
-11
lines changed

6 files changed

+99
-11
lines changed

docs/development-workflow/hyper-spec/01-installation.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@ end
1111

1212
Make sure to `bundle install`.
1313

14-
> Note: if you want to use the unreleased edge branch your hyper-spec gem specification will be:
15-
>
16-
> ```ruby
17-
> gem 'hyper-spec',
18-
> git: 'git://github.com/hyperstack-org/hyperstack.git',
19-
> branch: 'edge',
20-
> glob: 'ruby/*/*.gemspec'
21-
> ```
22-
2314
HyperSpec is integrated with the `pry` gem for debugging, so it is recommended to add the `pry` gem as well.
2415

2516
HyperSpec will also use the `timecop` gem if present to allow you to control and synchronize time on the server and the client.

docs/development-workflow/hyper-spec/03-methods-and-features.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ See the [Client Initialization Options](#client-initialization-options) section
7575

7676
By default the client environment will be reinitialized at the beginning of every spec. If this is not needed you can speed things up by adding the `no_reset` flag to a block of specs.
7777

78+
> Note if you are using `visit` to directly load a page and still want to use methods like `on_client` and the expectation helpers, see the last section on
79+
using visit at the end of this document.
80+
7881
# Details
7982

8083
### The `on_client` method
@@ -438,3 +441,11 @@ You can also run specs in a visible chrome window by setting the `DRIVER` enviro
438441
The method is typically not needed assuming you are using a multithreaded server like Puma. If for whatever reason the pry debug session is not multithreaded, *and* you want to try some kind of experiment on the javascript console, *and* those experiments make requests to the server, you may not get a response, because all threads are in use.
439442

440443
You can resolve this by using the `pause` method in the debug session which will put the server debug session into a non-blocking loop. You can then experiment in the JS console, and when done release the pause by executing `go()` in the *javascript* debug console.
444+
445+
### Using `visit` and the Application Layout
446+
Currently this is not well integrated (see [issue 398](https://github.com/hyperstack-org/hyperstack/issues/398)). If you want to visit a page on the website
447+
using `visit`, the following will not work: Timecop integration, and the `insert_html` and `before_mount` methods. You will also have to execute this line in your spec:
448+
```ruby
449+
page.instance_variable_set("@hyper_spec_mounted", true)
450+
```
451+
Upvote issue 398 if this presents a big problem for you.

release-notes/1.0.alpha1.6.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
## 1.0alpha1.6 - 2021-03-29
22

3+
| Release<br/>Date | Version | Open<br/>Issues | Documentation<br/>Sections<br/>Draft Ready | Documentation<br/>Sections<br/>WIP |
4+
|--------------|---------|-------------|-------|------|
5+
| March 29, 2021 | 1.0.alpha1.6 | 167 | 35 | 10 |
6+
7+
> Open issues includes enhancements, documentation, and discussion issues as well as few bugs.
8+
>
9+
> The documentation WIP (work in progress) numbers are approx, as more sections may be added.
10+
311
### New Major Features
412
+ Now compatible with Opal 1.x and Rails 6.x: Tested with Opal ~>1.0 + Rails ~>5.0 and Rails ~>6.0, and Opal ~>0.11 and Rails ~>5.0.
513
+ You can run Hypermodel connections on Redis (instead of ActiveRecord). This gives about a 10% performance boost, and there will be even better

ruby/hyper-operation/lib/hyper-operation/promise.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def resolve(value = nil)
123123

124124
begin
125125
if block = @action[:success] || @action[:always]
126+
@realized = :resolve
126127
value = block.call(value)
127128
end
128129

@@ -156,6 +157,9 @@ def reject(value = nil)
156157

157158
begin
158159
if block = @action[:failure] || @action[:always]
160+
# temporarily set values so always can determine if this
161+
# was a reject or resolve
162+
@realized = :reject
159163
value = block.call(value)
160164
end
161165

ruby/hyper-operation/lib/hyper-operation/railway/run.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ def step(opts)
6464

6565
def failed(opts)
6666
@promise_chain = @promise_chain
67-
.always { |result| apply(result, :failed, opts) }
67+
.always do |result|
68+
@state = :failed if @promise_chain.rejected? && @state != :abort
69+
apply(result, :failed, opts)
70+
end
6871
end
6972

7073
def async(opts)

ruby/hyper-operation/spec/hyper-operation/execution_spec.rb

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,42 @@ def self.promise
2828
expect(MyOperation.run(i: 1).tap { MyOperation.promise.resolve(2) }.value).to eq 4
2929
end
3030

31+
it "will chain rejected promises" do
32+
MyOperation.class_eval do
33+
def self.promise
34+
@promise ||= Promise.new
35+
end
36+
param :i
37+
step { self.class.promise }
38+
step { @took_a_bad_step = true }
39+
failed { |e| e unless @took_a_bad_step }
40+
end
41+
expect(
42+
MyOperation.run(i: 1)
43+
.always { |failure| failure }
44+
.tap { MyOperation.promise.reject("promise rejected") }
45+
.value
46+
).to eq "promise rejected"
47+
end
48+
49+
it "will chain promises that raise exceptions" do
50+
MyOperation.class_eval do
51+
def self.promise
52+
@promise ||= Promise.new.then { raise "exception raised" }.tap { |p| p.resolve }
53+
end
54+
param :i
55+
step { self.class.promise }
56+
step { @took_a_bad_step = true }
57+
failed { |e| e unless @took_a_bad_step }
58+
end
59+
expect(
60+
MyOperation.run(i: 1)
61+
.always { |failure| failure.message }
62+
.tap { } #MyOperation.promise.resolve }
63+
.value
64+
).to eq "exception raised"
65+
end
66+
3167
it "will interrupt the promise chain with async" do
3268
MyOperation.class_eval do
3369
def self.promise
@@ -217,7 +253,8 @@ def say_instance_hello()
217253
before(:step) do
218254
on_client do
219255
def get_round_tuit(value)
220-
Promise.new.tap { |p| after(0.1) { p.resolve(value) } }
256+
Promise.new.tap { |p| after(0.2) { value == :reject ? p.reject("promise rejected") : p.resolve(value) } }
257+
.then { |v| value == :exception ? raise("exception raised") : v }
221258
end
222259
module DontCallMe
223260
def called?
@@ -260,6 +297,40 @@ def say_hello
260297
end.to eq 4
261298
end
262299

300+
it "will chain rejected promises" do
301+
expect do
302+
Class.new(Hyperstack::Operation) do
303+
param :i
304+
step { get_round_tuit(:reject) }
305+
step { @took_a_bad_step = true }
306+
failed { |e| e unless @took_a_bad_step }
307+
end.run(i: 1).always { |failure| failure }
308+
end.on_client_to eq "promise rejected"
309+
end
310+
311+
it "will chain promises that raise exceptions" do
312+
expect do
313+
Class.new(Hyperstack::Operation) do
314+
param :i
315+
step { get_round_tuit(:exception) }
316+
step { @took_a_bad_step = true }
317+
failed { |e| e unless @took_a_bad_step }
318+
end.run(i: 1).always { |failure| failure }
319+
end.on_client_to eq "exception raised"
320+
end
321+
322+
it "will interrupt the promise chain with async" do
323+
expect_promise do
324+
Class.new(Hyperstack::Operation) do
325+
param :i
326+
step { get_round_tuit(2) }
327+
step { |n| params.i + n }
328+
step { |r| r + params.i }
329+
async { 'hi' }
330+
end.run(i: 1)
331+
end.to eq 'hi'
332+
end
333+
263334
it "will interrupt the promise chain with async" do
264335
expect_promise do
265336
Class.new(Hyperstack::Operation) do

0 commit comments

Comments
 (0)