These are chat archives for opal/opal

29th
Apr 2016
Austin Erlandson
@erlandsona
Apr 29 2016 00:28
Nvmnd! I got it! I just had to add config.opal_spec.spec_location and modify the opal-rspec-rails gem locally so that I could use the .opal naming convention which is important if I want to eventually put regular rspec’s in the same directory as well… eg: feature/controller_spec.rb vs feature/browser_spec.opal
I would want the opal runner to run opal specs for now and rspec to run regular specs.
@fkchang ^ Yay!
Austin Erlandson
@erlandsona
Apr 29 2016 00:54
Well sort of… I got a single spec to run but I’m trying to get some actual tests to run and I can’t instantiate the object I’m trying to test… :/
Elia Schito
@elia
Apr 29 2016 08:26
@erlandsona I'm not really familiar with trailblazer, having some example code to look at would make it easier
Barrie Hadfield
@barriehadfield
Apr 29 2016 09:23
@erlandsona have a look at http://reactrb.org/ as react components map very nicely to TRB cells (conceptually as view models). I am also using TRB concepts for the back end and have replaced my entire UI from Cells to React components using react.rb and I am never looking back!
Austin Erlandson
@erlandsona
Apr 29 2016 13:07
@barriehadfield do you have an example app with TRB and React.rb I could look at? I'm dying to try out React.rb but I can't seem to get the ecosystem set up. Is React.rb pretty easy to write opal-rspecs for?
Brady Wied
@wied03
Apr 29 2016 14:12
@erlandsona - It's not hard to write RSpec tests for React components. I have 500 of them. To my knowledge, there isn't a shared approach yet but it's not hard using the wrappers react.rb already has for React test utils
it can be trickier if you use a lot of stateful components (as opposed to the Redux/Grand Central way)
Barrie Hadfield
@barriehadfield
Apr 29 2016 14:18
@erlandsona I will publish a sample app over the weekend for you. It did take some time to get the echosystem all working but I have eventually settled on using a combination of some gems (with Sprockets) and most of the front end assets beling delivered by Webpack. I would love to get 100% Webpack for the FE and am eagerly watching Opal progress here.
Brady Wied
@wied03
Apr 29 2016 14:20
Barrie Hadfield
@barriehadfield
Apr 29 2016 14:22
yes, I am very excited about that. I have not tried it yet and wondered if it would play nicely with the react.rb approach?
Brady Wied
@wied03
Apr 29 2016 14:24
I can't speak to Reactive record and all that stuff, but the core React.rb should work fine
Barrie Hadfield
@barriehadfield
Apr 29 2016 14:25
would there be any special considerations? (I had been thinking I would have to remove the react.rb gem and go 100% webpack).
Brady Wied
@wied03
Apr 29 2016 14:27
no. if you did that, you'd have to write React components the JS way
React.rb GEM and opal webpack do not do the same thing. Webpack, if you use it a runtime, is more of a replacement for sprockets than it is React.rb
I only use it to run tests with Karma right now
Barrie Hadfield
@barriehadfield
Apr 29 2016 14:28
excellent news
Austin Erlandson
@erlandsona
Apr 29 2016 14:51
@barriehadfield are you available to do like a hangout and take a look at the system by any chance?
Barrie Hadfield
@barriehadfield
Apr 29 2016 14:57
@erlandsona sure - happy to do that. message me privatly and we can set it up
Austin Erlandson
@erlandsona
Apr 29 2016 16:21

So @barriehadfield and I were not able to get the specs to run… anyone else want to jump on a hangout with me and try to figure it out?

@wied03 I’m super close just can’t quite get the spec to recognize the file I’m trying to test and I’ve tried requiring but no luck...

I’ve got config.opal_spec.spec_location = 'app/concepts’ in config/application.rb

I bundle opened opal-rspec-rails and patched the opal/opal-rspec-rails-runner.rb.erb file to recognize **/*_spec.opal instead of **/*_spec.rb files… which works well.

And that config works without a spec_helper. But this is the part where I think I need a spec_helper to load all the opal source so I can test it from my _spec.opal files as currently the classes I have defined in my source files are not available in the _spec scope.

Thoughts?

Brady Wied
@wied03
Apr 29 2016 16:31
@erlandsona - you have to require what you're testing from your specs no matter what. that's true for anything outside of Rails autoload
now if that doesn't throw a sprockets error, then sprockets is including your impl
Austin Erlandson
@erlandsona
Apr 29 2016 16:31
yeah I’m getting the sprockets error page when I add the require ‘infinite_scroll’ at the top of the infinite_scroll_spec.opal file
Brady Wied
@wied03
Apr 29 2016 16:36
is infinite_scroll in your Opal load path ?
Austin Erlandson
@erlandsona
Apr 29 2016 16:38

Not exactly sure how to answer that. The code for the infinite scroll works EG: the page infinitely scrolls and there’s no JS that would make that happen… But it may not be in the load path for the specs…

Stupid question but how do I determine the load path?

Brady Wied
@wied03
Apr 29 2016 16:38
# config/initializers/opal.rb
Rails.application.config.assets.paths << Rails.root.join('app', 'views', 'shared').to_s
you would need to have something like that
this is from the opal-rails site
in opal-rails case, the Opal load paths all end up in sprockets' load path, which is what Rails.application.config.assets.paths is
one of the directories in that load path needs to contain 'infinite_scroll' for this to work
Austin Erlandson
@erlandsona
Apr 29 2016 16:40
It should… Let me double check though...
Brady Wied
@wied03
Apr 29 2016 16:40
and it can't be in a subdirectory or what not unless that subdirectory is in your load path or you require it differently than you are
this may be working differently at runtime if you're using sprockets //=require stuff and relative stuff in something like application.js
Austin Erlandson
@erlandsona
Apr 29 2016 16:41
I’m assuming you don’t have a second to screenshare?
Brady Wied
@wied03
Apr 29 2016 16:42
correct, i'm working :(
I could look without audio though
Austin Erlandson
@erlandsona
Apr 29 2016 16:43
Haha hey me too! :+1: for $. Alright that could work.
Austin Erlandson
@erlandsona
Apr 29 2016 17:31

Yay! @wied03 is the bomb! Turned out it the specs didn’t have jQuery available…

I think we just need to add documentation that iterates on this
http://rubyist.jaredwhite.com/2015/07/22/how-to-introduce-opal-gently-into-a-legacy-rails-app/

But that also explains the responsibility of the spec_helper. EG: It’s supposed to add the necessary require statements for dependencies that will be used by all you’re specs. And that also you need to require the spec_helper and whatever file you’re testing at the top of your spec file.

At least initially until there’s a good solution for meta-programming those import statements that could be built into the opal-rspec-rails gem.

Those are my thoughts.

Brady Wied
@wied03
Apr 29 2016 17:33
To follow up on what @erlandsona said, I created an issue here - opal/opal-rspec-rails#2
Austin Erlandson
@erlandsona
Apr 29 2016 17:45
@wied03 what’s the rake task for running opal specs? Or will they just run as rspecs?
EG: right now I run bundle exec rspec to run my specs… is there something specific I should do for opal?
Brady Wied
@wied03
Apr 29 2016 17:52
they will not run as rspecs
bundle exec rake opal:spec usually
i'm not sure if opal-rails or opal-rspec-rails still include the rake task
Austin Erlandson
@erlandsona
Apr 29 2016 17:54
But since it’s not the spec directory would that matter?
Also does opal have a require_tree equivalent?
Brady Wied
@wied03
Apr 29 2016 17:56
maybe elia is still working on that for opal-rspec-rails. in any case, you can just declare your own inside lib/tasks/some_fille.rake like this:
Opal::RSpec::RakeTask.new('opal:spec' => :environment) do |server, task|
  app = Rails.application
  task.files = FileList[
      app.root.join('spec/javascripts/**/*_spec{,.js}.{rb,opal}')     
  ]
  task.default_path = 'spec/javascripts'
  app.assets.paths.each { |p| server.append_path p }
  %w(spec/javascripts).each { |p| server.append_path p }
end
Austin Erlandson
@erlandsona
Apr 29 2016 17:57
Sweet!
Brady Wied
@wied03
Apr 29 2016 17:57
this is following the same stuff that's on the opal-rspec page. only difference with rails is the dependency on the environment task and app.assets.paths.each { |p| server.append_path p }
yes, require_tree works in opal
Austin Erlandson
@erlandsona
Apr 29 2016 17:59
Alright working it out now! Got 8 green specs so far! WooooHooo!!!
Austin Erlandson
@erlandsona
Apr 29 2016 18:10
So I’m getting uninitialized constant Opal::RSpec::RakeTask? Thoughts?
Brady Wied
@wied03
Apr 29 2016 19:11
require the rake task first
see opal-rspec page
Austin Erlandson
@erlandsona
Apr 29 2016 19:41
Got it. Thanks!
It worked! Yay!