How to generate cucumber-rails for a different folder - ruby-on-rails

I'm trying to create a test folder for my rails project using cucumber-rails generator (the gem is here: https://github.com/cucumber/cucumber-rails ).
The problem is that when I run "rails generate cucumber:install" it creates a folder in my project named "features" with the cucumber files inside that folder, which is - in my perspective - not very organized.
I would like all the cucumber files to be inside a folder named "test". Is there a way that allows me to do that? I tried to run the generator inside the "test" folder but it didn't seem to work.
Anyone knows how to do this? Thanks a lot!

There are essentially 3 test libraries in Ruby and corresponding common assumptions:
test is expected to contain Test::Unit or MiniTest tests
spec is expected to contain RSpec tests
features is expected to contain cucumber tests
You should follow these assumptions or you may end up having several troubles in the long run.
In any case, to answer your question, what you want to do is not possible. The features folder is hard-code in the generator and in the cucumber task file. Therefore, unless you want to introduce several hacks and workaround, you'll have to follow the conventions.

I think there is a pretty straight forward solution for this:
In an issue it is pointed out that we can point to different paths for our features in the cucumber.yml
default: features
// becomes
default: test/features
But, then it can't find the step_defintions if you also add your custom path as a required flag then it can pick up the step_defintions as well.
default: features
// becomes
default: test/features -r test/features/step_definitions
if you don't want to use cucumber.yml you can use the cucumber cli to take care of it:
bundle exec cucumber test/features -r test/features/step_definitions
NOTE: I am using this in a docker environment and this works fine for both local and docker implementations.

Related

How to test generators with RSpec

Is there a recommended way of testing Rails generators with RSpec?
The only solution I've found is the Generator Spec gem, that hasn't been updated in over two years.
There's the gem
https://github.com/petergoldstein/generator_spec, which does a decent job, although it is not very actively maintained
I would write a file by hand that acts as a test fixture. I would then as part of my test generate the file with the generator. At that point I would diff the two files. Looks like the diffy gem could help you there. If there is no diff then pass the test. Fail if otherwise.
https://github.com/samg/diffy
Don't forget to clean up your temp files after the tests. You don't want them hanging around in your repos.
I didn't found official recommendations how to test Rails generators too. So, I am just run generator directly on dummy application, compare generated files and delete them at the end of test.
Here is my spec which implement described approach. I had used minispec instead of rspec here but they a very similar.

Why won't my features specs run in RSpec?

In my Rails 4 app, I'm using Rspec for testing. My directory structure is
spec
-- controllers
-- factories
-- features
-- spec_helper.rb
-- support
When I run rspec spec, it runs my tests in controllers, but not in features. I can specify rspec spec/features and they'll run, but I want to be able to run all tests under spec at once. My guess is it's not looking in features because of a configuration setting, but I don't know where this is.
I've tried different incantations of starting rspec but haven't had any luck.
Based on your feedback to the comments above, the issue is one of file naming. I've definitely been burned by that before too. By default Rspec will go through the files looking for ones ending with _spec.rb, this default behaviour is overridden if you specify the folder manually.

rubymine only able to run model tests one by one

I am able to right-click on any of my 3 spec/models but when I right click the spec/models folder and select 'run all tests in models' I get 'Unable to attach test reporter to test framework'.
The first line of my model tests is: require 'spec_helper.rb'
I posted this answer for another question. It may help with this one as well:
On my system, the problem was the "redgreen" gem. It automatically colors the progress marks (dots) and the Test::Unit summary messages based on success or failure. There must be something in RubyMine that's trying to parse the Test::Unit results (the output of "rake test", I imagine), and it's choking on the ANSI sequences.
I commented out "require 'redgreen'" in my test/test_helper.rb, and the problem went away. I really like redgreen for executing "rake test" from the shell, though, so I put this in test_helper to make it work for both "rake test" and within RubyMine:
require 'redgreen' if $stdin.tty?
It may not be redgreen that's causing your problem, but be suspicious of anything which might create unconventional Test::Unit output.
Good luck!
I had the same issue and had to add the following to /etc/launcd.conf (I had to create this file as well):
setenv DYLD_LIBRARY_PATH /usr/local/mysql/lib/
and reboot. There are other ways to do it as well (a plist file, adding this environmental variable to RubyMine, etc… but this was most reliable. Of course, this assumes that you use MySQL.
The answer in the end for my setup was to fiddle around with the IDE settings including the ruby version, making sure it was 1.9.2 and the directories referenced in the config. screens were correct. This plus some restarts resolved the issue.

Adding custom directories (source and spec) to autotest in a Rails 3 project

I have a Rails 3 app that uses RSpec2 as my testing framework, and I'm able to use autotest to watch my model and spec directories for changes and re-run my spec suite when files change.
I'd like to add a directory with some custom classes in it (RAILS_ROOT/lib/some_project/lib/.rb) and their corresponding specs (RAILS_ROOT/spec/some_project/_spec.rb) so that autotest will automatically pick up changes to all of those files and re-run as needed.
How do I get autotest to watch these files in these other directories? I suspect I have to add something to RAILS_ROOT/autotest/discover.rb, but I'm not exactly sure what to do.
This looks like what you want to do:
http://seandenigris.com/blog/?p=337

Rails 3 RSpec 2 NetBeans integration

NetBeans 6.9 provides a custom Runner class for RSpec to be integrated into the IDE. I'm trying to get my Rails 3 applications specs to be correctly displayed inside NetBeans, but RSpec 2 seems no longer to support custom Runner classes in general.
Any ideas how to get the specs into the IDE anyway?
Just in. Oracle has just announced they are withdrawing support for Rails in future version of NetBeans. Time to start looking at other IDE options.
http://news.ycombinator.com/item?id=2148161
So far (NB 6.9.1) the only way I know to run Rspec2 tests from inside NetBeans is by using rake tasks. But I was not able to make it work with UI Test Runner, because of this and few other problems. So the best way is to avoid invoking UI runner, this can be done in many ways:
Disable it via tools -> options -> miscellaneous -> Ruby
modify project.properties file
give other name to task than 'spec', so naming task as 'rspec' will avoid invoking UI runner
This way you will have just test results in output pan, but it is still usable, because you can click anywhere on stack trace, and NB will take you immediately to that file:line.
There is one thing left, auto generated by NB Rakefile has not valid task (for Rails projects, there is NO such problem), to make it work one needs at least:
require 'rspec/core/rake_task'
Rspec::Core::RakeTask.new(:rspec)
I know this is not what you are expecting but you might want to check RubyMine3 out it comes out of the box, you do need to buy a licence but at least you can check it out in the 30 day trial
I am using RVM.
And at the minimum I wanted to be able to run my Ruby 1.9.2 / Rails 3 / RSpec 2 specs from inside the IDE and be able to click on stack traces for Netbeans to open the right files and lines.
I found a work-around for that:
Put somewhere in the project a ruby file that shells out to run the spec suite.
E. g. my ruby file has the following content:
system <<EOF
time ~/.rvm/wrappers/ruby-1.9.2-p290#default/rspec --drb spec
EOF
Change the ruby version and gemset as you need it.
The major limitation:
I cannot just run only a single spec. For that I have to change the "spec" parameter to the target spec file (which isn't such a big deal though).
Netbeans is fairly sluggish running specs (using rspec1 here), would recommend running specs from command line.

Resources