I'm building a Rails 3 app. I'm trying to learn Cucumber with Capybara.
Do I need JRuby to run Capybara via Cucumber?
I've used Webrat, but many people seem to be using Capybara,
so I'd love to try.
I don't need JavaScript testing right away, but I want to install
Capybara if I need in the end.
I read and read the Capybara documentation, but couldn't understand.
Capybara does not require jRuby or the Selenium-RC drivers.
Simply do the following to setup Cucumber with Capybara.
$ gem install capybara cucumber
$ rails generate cucumber --capybara
I haven't used Capybara myself, but from what I can glean from the readme, it doesn't look like it requires JRuby, depending on the JavaScript driver you use. For instance, if you want to use Culerity, then yes you need JRuby, since it needs to be in your path.
Are you having difficulty installing Capybara?
Related
The Problem:
I have a Rails application and I can successfully run the RSpec suite using rspec spec. I've also made a neat little gem that also has a pretty little copyright next to it. Its not open source. Its a gem that belongs to that Rails application and that Rails application only.
Now, this gem has some specs and it also pumps out a nice string of green. So, to test the whole application I might do:
$ rspec spec
$ cd custom_gem && rspec spec
That's nice, but what if I want to run the whole suit from one line? Well I could do:
$ rspec spec custom_gem/spec
But, this doesn't work in my case because the gem is also a Rails engine. Due to this, it has to connect to a dummy application within the gem.
Now that you know this, I can finally ask my key question:
How do you run a spec for a rails engine and the spec for your main application given that your rails engine should also have a dummy application to test upon?
If both of them are running correctly on their own, why not just make a bash alias?
alias test_all='cd /full/path/to/gem && rspec spec && cd /full/path/to/rails && rspec spec'
I'm running a Rails 2.3.4 app under ruby 1.8.7 and rvm with a custom gemset.
In trying to get rspec up and running, I've tried several times to uninstall rspec 2 and install rspec and rspec-rails version 1.3.4. However, when I run rspec -v I get 2.10.0 regardless of what I do.
Finally I got this error message:
You are running rspec-2, but it seems as though rspec-1 has been loaded as
well. This is likely due to a statement like this somewhere in the specs:
require 'spec'
Please locate that statement, remove it, and try again.
So it looks like 2.10.0 is actually still loaded. Even if I do a gem uninstall rspec rspec is still loaded. What's going on?
You should use spec (the RSpec 1 executable) instead of rspec, as explained in this answer.
I am working on moving our celerity based integration tests to capybara-webkit.
The documentation provided on git-hub (https://github.com/thoughtbot/capybara-webkit) for capybara-webkit was helpful but i am unable to run my tests, ending up with error for jruby:
NotImplementedError: fork is not available on this platform
org/jruby/RubyKernel.java:1792:in `fork'
Is there a way I can get capybara-webkit work with jruby?
You could try poltergeist which also provides a headless webkit driver for capybara, but does not rely on any native extensions. Instead, it uses PhantomJS to drive the tests. According to the README jruby is supported.
This is a bit of a long shot but have you tried gem 'spoon' in your Gemfile?
I have not been able to get capybara-webkit working with JRuby. I have had success using MRI for my development/TDD cycles and switching to JRuby (using RVM) to make sure everything still runs. When I run my JRuby features (cucumber), I just use selenium for testing javascript. I have a bit of setup code that looks similar to this in features/support/setup.rb:
Before do
if running_in_jruby
Capybara.javascript_driver = :selenium
else
Capybara.javascript_driver = :webkit
end
end
This is specific to cucumber of course, although you should be able to do something similar with rspec. I've found that MRI is quite a bit faster at running my tests due to the faster startup time vs. Java. I'll run my features/specs many times during the development of a feature, and then before I check in I'll switch to JRuby and run the tests just once.
I've started a project on rails, and so far I'm testing it using rails' built in test suite. Is there a way to start testing it using rspec and cucumber at this point? How to do this?
Thanks!
This is a really weird question. What do you mean you've been using Rails' built-in test suite? What version of Rails are you using?
To start with testing, say models, in RSpec, you invoke the following command in Rails 3:
rails generate rspec:model <ModelName>
In Rails 2.x:
script/generate rspec:model <ModelName>
Cucumber is a bit different, but it starts with (Rails 3):
rails generate cucumber:install
Rails 2.x:
script/generate cucumber
All of this information is easily accessible on their respective Github pages. Is there anything more specific you need?
I have been following an RSpec tutorial on one of my machines, in the hope of learning more about BDD and TDD. My setup was with Rails 2.2.2 and Rspec 1.1.12
Tonight I decided to continue on my primary machine and moved my code from my portable to my desktop. Not having RSpec, i installed the gem . . .
sudo gem install rspec
sudo gem install rspec-rails
Strife and Calumny! The new version of Rspec installed! 1.2.0! And now my tests are failing all over the place! While I fully intend to follow up and learn the most up to date version, I would really like to complete what's left of the tutorial without having to start over. I am wondering. Is there a way to install and specify that I would like to run my code against the previous Rspec, 1.2.12?
You could uninstall and reinstall with VERSION specified. Explained here.
If you want to have more than one version on your computer, for if maybe you should have a 2.2 rails app and a 2.3 rails app then in your environment.rb file specify:
config.gem, 'rspec', :lib => 'spec', :version => '1.1.12'
and your application will use that gem spec and the rspec-rails gem that goes with it. This will enable you to use the appropriate gem for each appliction.
In addition to specifying the rspec and rspec-rails versions in my environments/test.rb file, I added script/ in front of spec, e.g.:
script/spec spec/controllers/treasury_accounts_controller.rb
to get past this error:
/opt/ror/ruby-ee-1.8.7-2011-03/lib/ruby/site_ruby/1.8/rubygems.rb:335:in `bin_path': can't find executable spec for rspec-2.1.0 (Gem::Exception)
from /opt/ror/ruby/bin/spec:19