Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

something wrong with set_timeout in specs #58

Closed
jaredcwhite opened this issue Nov 7, 2014 · 6 comments · Fixed by #59
Closed

something wrong with set_timeout in specs #58

jaredcwhite opened this issue Nov 7, 2014 · 6 comments · Fixed by #59

Comments

@jaredcwhite
Copy link
Contributor

I'm trying to run the test suite using rackup in the browser (using latest master), and it seems like something odd is happening with the async/set_timeout stuff. First of all, it seems the numbers are being interpreted as seconds, not millseconds, so set_timeout 400 do will take 400 seconds to run. (I can change it to 4, and it will run in 4 seconds...) Also, when there's an error inside the block, instead of updating the page, it throws an actual error visible in the JS console.

Anyone else able to see this issue?

@adambeynon
Copy link
Contributor

Hi Jared. When things run async in javascript, we can't have a top level wrapper that will catch issues in all browsers. There is also an instance async method which you can use which will catch any errors:

describe "some async magic" do
  async "it might raise an error" do
    something_happens_later do
      async { raise "yo" }
    end
  end
end

Wrapping things inside that async block will make things work as they are meant to.

@jaredcwhite
Copy link
Contributor Author

Thanks for the helpful tip...doesn't really explain my problem however because I didn't write any of the code that's not working right, particularly the strange set_timeout behavior. :)

@adambeynon
Copy link
Contributor

The timeout behaviour is intentional. Maybe it should be renamed though to avoid confusion withsetTimeout

@jaredcwhite
Copy link
Contributor Author

Thanks Adam, that put me on the right path. I renamed set_timeout to delay (since set_timeout was actually just an alias of delay) and changed the values. I also fixed the other issue you mentioned by putting async { } inside the delay blocks instead of wrapping them.

@adambeynon
Copy link
Contributor

Just to follow up, the reason that method deals with seconds instead of milliseconds is that it feels a bit more consistent with other ruby/rails libs:

# ruby corelib
sleep(1)    # => 1 second

# rails monkey patching
12.seconds.to_i   # => 12

@jaredcwhite
Copy link
Contributor Author

Yeah, I think it just threw me seeing "set_timeout" since that has such a specific usage in Javascript. And apparently I wasn't the only one confused since the tests weren't working. Less confusing to call it delay. :) Thanks again for the tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants