Evergreen + jasmine-jquery - ruby-on-rails

I want to make use of the new json fixtures ability of jasmine-jquery, but can't get it to work. I have a Rails 3.2 app with evergreen for JS testing. As the readme of https://github.com/velesin/jasmine-jquery said, putting the jasmine-jquery.js inside the spec/javascripts/helpers dir would load jasmine-jquery automatically.
I put jasmine-jquery (and other libraries like jasmine-ajax) into
spec/javascripts/helpers dir (so they are automatically loaded) and
fixtures into spec/javascripts/fixtures dir.
But it doesn't. I tried to load the file inside the spec_helper.js, but the require only points to the public dir.
I also found this answer: https://groups.google.com/forum/?fromgroups=#!topic/ruby-evergreen/0Tma5RKqZB8
But the solutions aren't working in my case.
So, where can I tell evergreen / jasmine to load the jasmine-jquery.js file, so that I can use the loadFixtures methods...?

Related

A way to display a list of public assets

(Been looking for this for ages over internet...).
Been working with very old npm packages recently and seems that they cannot be loaded properly within Rails-6 (I know I could create a question by each cases, but I'd like to learn to handle this myself since every time it is for a different reason).
I'd like (as for debugs and in development mode only) to display the list of available all assets, including js, css, images, and anything else available at public level (the client could load). So it should be a set of compiled assets ?
Similarly to http://localhost:3000/rails/mailers like http://localhost:3000/rails/assets ?
Displaying the list of all available assets (prior compilation, also for debug intents) could also be great.
This might do what you want:
Rails.application.assets.each_file do | pathname |
# ...
end
This will enumerate every file of which Sprockets is aware. You can run that at rails c or build a simple controller to dump the list into a view if you prefer. For more information, see https://stackoverflow.com/a/11005361.
If you're not using Sprockets (e.g. a newer Webpacker-based application) then, obviously, you'll need a different solution.
You can run rails assets:reveal and see all the available assets:
$ rails assets:reveal
application.js
application.js.map
application.css
application.scss
...
To view the full path, use rails assets:reveal:full:
$ rails assets:reveal:full
/home/{REDACTED}/app/assets/builds/application.js
/home/{REDACTED}/app/assets/builds/application.js.map
/home/{REDACTED}/app/assets/builds/application.css
/home/{REDACTED}/app/assets/stylesheets/application.scss
...

Organize GraphQL files in directories in Rails

Upon running rails g graphql:install, a set of useful base type files are created in /app/graphql/types for us to extend when defining our own types. When running any of the generators, it creates these files in the same folder also. I set about creating sub directories thinking I could add some sense to this giant catch-all directory, but couldn't get things to load properly.
Since there is a base file for each type (base_enum.rb, base_object.rb, etc.), I created a folder for extensions of each of these types (enum_types, object_types, etc.). This broke auto loading though and I had to explicitly import these files to be able to use these custom types. So, at the top of query_type.rb, mutation_type.rb and app/graphql/mutations/base_mutation.rb I added the following:
['enum_typs', 'input_object_types', 'interface_types', 'object_types', 'scalar_types', 'union_types'].each do |dir|
Dir[File.dirname(__FILE__) + "/#{dir}/*.rb"].each {|file| require file }
end
This allowed things to run, but any change would break auto loading so I would have to restart the server on each change. I started reading through this article about auto loading on the rails site, but it was quite honestly a little over my head. Though it led me to believe I had to either find the correct names for my folders or namespace the objects defined in my type definition files properly to be able to do this.
Is there a sane way to organize these files in sub-directories which doesn't break auto loading? Do most projects just have a flat folder structure for these files?
Thank you!

Ember App Kit 'validate-imports' task blows up when using coffee-script

I have renamed app.js to app.coffee (as well as translated the contents), but now when I compile I get this error:
Running "validate-imports:tests" (validate-imports) task
>> client/tests/helpers/start-app: Cannot find module "client/app"
This error goes away when I translate the file back to javascript.
I have added the grunt-contrib-coffee and confirmed it works correctly, the problem I believe is that the coffee-script compilation happens after the validate-imports task which looks for .js files in the app folder. Does this need to be tweaked to look in the tmp/javascripts folder where the coffee-script gets compiled to?
Here is the task in question:
// Scripts
grunt.registerTask('buildScripts', filterAvailable([
'jshint:app',
'jshint:tests',
'validate-imports:app',
'validate-imports:tests',
'coffee',
'emberscript',
'copy:javascriptToTmp',
'transpile',
'concat_sourcemap'
]));
Anyone know of this bug?
I found an answer here. Thus, when I tried it, I renamed start-app.js to start-app.coffee, converted the code into coffescript and now it works without that error.
Bryan
One approach to this would be to add this line to your testem.json file:
"before_tests": "coffee -c tests/**/*.coffee"
This should compile the .coffee files within your /tests directory before test execution, meaning they will compile down to their .js equivalent before they are run. While you could technically change the EAK boilerplate from .js to .coffee with a similar trick, it might be better just to write your tests in .coffee, while leaving the default .js testing harness to maintain compatibility with EAK.
You can also remove these files when the test run is over, as shown within the tapas-with-ember testem.json file.

rails console error require './example_user'

I'm using the railstutorial at http://ruby.railstutorial.org/chapters/rails-flavored-ruby#sec:a_user_class
I've been told to type require './example_user' but... I get this error
LoadError: cannot load such file -- example_user
from /Users/snook3/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in require'
and then further and further errors
I imagine that I'm not linking correctly to that folder, can anyone let me know where I should be linking too?
Yes, just move the file to the actual root directoy. Doing mv example_user.rb* / should do it.
Also, don't worry if after requiring the file, you get a return of "true" instead of ["User"].
You can use
Rails.root
to get your current Rails project root.
So
require Rails.root + 'path_to_example_user'
would load the file.
You can also try the reload! command, which will reload the whole Rails environment.
The file should end with .rb:
require './example_user' #will not work
require './example_user.rb' #will work
To rename the file, use the following command line (not in the rails console):
mv example_user example_user.rb
try using absolute path for the file... something like this:
require '/Users/snook3/my/project/folder/example_user.rb'
No need to specify the full path, simply append .rb to the filename: require './example_user.rb'.
I had this exact same problem, but not being very familiar with Unix I can only explain it like this.
1) I created the example_user.rb file in Sublime Text 2 and saved it to the application root folder.
2) The "require" wasn't working for me, just like the OP. Even though I could see the file there in the folder.
3) However, opening up a Terminal window, navigating to the application root, and entering "dir", I could then see that the filename had a "/ " before it!? Not sure how/why that happened, or why it wasn't visible in Explorer (or whatever the Unix equivalent of that is called--Nautilus?).
4) After renaming the file from within Terminal, it all worked. But would love an explanation of what went wrong if this makes sense to any of you Unix/Rails folks.
Try
touch example_user.rb
in Unix terminal. And then add code to this file.
The tutorial tells you to "create the file example_user.rb in your application root directory". I mistakenly initially put it in the app folder and got the same error message.
If you instead move the file into your project root directory, then require './example_user' will work.

How to put capybara output html to a specific folder?

When I use the "Show me the page" step, with Capybara / Cucumber, can I control where the files get output? I can't seem to find the config for this, and my google fu is failing me.
Right now it appears that by default they go to the root of my rails folder and clutter up things there.
There is indeed a config option that allows you to specify where to output the files:
Capybara.save_and_open_page_path
I believe it was added in the latest version (0.3.9)
In your env.rb file you can do something like:
Capybara.save_and_open_page_path = '/Users/jsboulanger/my-rails-project/tmp'
In Capybara 2.10, Capybara::save_and_open_page= is deprecated. Instead, call Capybara::save_path=
Nice. Thanks for this.
To be really neat about it I added the config line to config/environments/test.rb, since you generally only use capybara in test, and that works fine.
Since there's a bunch of subfolders in tmp/ I used:
Capybara.save_and_open_page_path = 'tmp/capybara'
and created that folder.

Resources