How to put capybara output html to a specific folder? - ruby-on-rails

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.

Related

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.

Evergreen + jasmine-jquery

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...?

Sprockets::FileNotFound when trying to include a jQuery gem

I'm trying to use https://github.com/linjunpop/jquery-tablesorter-rails to sort my tables. I'm running into issues when trying to include the CSS:
/*
* = require jquery-tablesorter/blue
*/
Error message:
Sprockets::FileNotFound: couldn't find file 'jquery-tablesorter/blue'
I do see the Gem being loaded in the config path:
1.9.3p194 :008 > Rails.application.config.assets.paths.each { |x| puts x }
.rvm/gems/ruby-1.9.3-p194/gems/jquery-tablesorter-1.0.5/vendor/assets/images
.rvm/gems/ruby-1.9.3-p194/gems/jquery-tablesorter-1.0.5/vendor/assets/javascripts
.rvm/gems/ruby-1.9.3-p194/gems/jquery-tablesorter-1.0.5/vendor/assets/stylesheets
Any idea what the issue could be?
Can't reproduce. Usually when this kind of things happen to me is because of forgetting to restart the dev server after bundling a new gem. Sprockets tries to build or resolve a new set of assets, but the loaded environment is the same as before, so the additional asset can't be found.
The corret path is:
*= require jquery-tablesorter/theme.blue
I've updated Tablesorter to use themes in version 2.4+, so the blue theme file has been renamed and moved to a different directory.
I don't know much about Ruby, or that repo but you might want to get Tablesorter v2.3.11 until that repo has been updated (see this issue in that repo).
I'm seeing the path you're requiring as a directory; the error message seems to indicate that it's failing to find a file. Have you tried
*= require jquery-tablesorter/blue/*
instead?

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.

Vim E854: path too long for completion

I have a Rails RSpec file which looks something like
require 'spec_helper'
describe "Something" do
...
end
When I try to use Ctrl+N to autocomplete anything in that file, I get:
Text version:
Scanning included file: spec_helper.rb
E854: path too long for completion
Press ENTER or type command to continue
If I Ctrl+C this, it completes my word perfectly.
To avoid Vim to autocomplete by using included files I can do:
:set complete-=i
But that's not the root of the issue.
How can I fix this?
Ok,
It results that I am using MacVim, and like romainl commented in the original post, the issue is related to a bug in ruby.vim. In this Stack Overflow post the third answer candidate actually suggests a possible cause (correctly), which is related to a bug in ruby.vim ( an old version is using a deprecated function ).
MacVim (Snapshot 64) is supplied with the old rails.vim, so to fix this I went into MacVim.app/Contents/Resources/vim/runtime/ftplugin and did wget to the raw file in the official rails.vim plug-in repo
This fixed the issue for me.

Resources