How to make cucumber-rails use watir-webdriver instead of Capybara - ruby-on-rails

I have been searching for a simple answer to this for a few days and can't seem to find an one, on either stackoverflow.com or google. So, firstly, if this is answered elsewhere please point me in the correct direction.
So, I have a relatively new Rails 3 project using the cucumber-rails gem. I am relatively new to Rails but have experience in Ruby and other web frameworks such as Sinatra and Ramaze. My understanding is that out of the box, cucumber-rails uses Capybara for interacting with the web application and somehow does this without starting the rails server. It somehow interacts with rack to simulate the requests. Not sure if I have that entirely correct but I'm pretty sure it does not need a running rails server.
I am not a great fan of the Capybara DSL and I much prefer watir-webdriver which I have used in a few non rails projects (and non Ruby projects even). However, I have not been able to find anywhere to show me how to swap out Capybara for watir-webdriver.
So my questions are these:
Does the cucumber-rails gem have the ability to swap Capybara out for watir-webdriver?
If so, what is the best way to do this?
If not, does that mean I need to ditch cucumber-rails and just set cucumber with watir-webdriver up in my project manually?

Well, it doesn't look hopeful from the project description:
Rails Generators for Cucumber with special support for Capybara and DatabaseCleaner
And sure enough, it explicitly, unconditionally, loads Capybara here
I think that means that you're going to need to hook it up yourself.
Having said that, I don't think there's anything stopping you from installing the gem, running rails g cucumber:install, and then replacing the Capybara-specific bits in the files it produces.

Related

Alternative to turn gem for rails MiniTest

I've recently upgraded to Rails 4.2.0 and MiniTest ~> 5, and that broke the Turn gem. I noticed that it is no longer being maintained due to the developers getting fed up with API changes https://github.com/turn-project/turn , so I pulled it out of my project.
I'm really missing the better test output that Turn provided. What are some great alternatives to get customizable, colorized, well-structured MiniTest output?
Take a look at minitap and tapout - it's not a simple plug-and-play gem like turn was, but you can get it very nice with a bit of trial and error.

Load Rails 3 test fixtures into development database

I have a nice set of fixtures that I use for testing. When a request test fails it is handy to run the app interactively with the test fixtures loaded. But if I run the full server with -e test I get all kinds of crazy errors, probably having to do with the pipeline.
-- edit --
When I visit the home page I get this in the browser:
I say it's crazy, because I don't understand it :) In particular, I am using twitter-bootstrap and I am unclear about sass/scss/css work with Twitter Bootstrap + Rails so it's highly likely that I have some detail wrong in how I am using them together (or that the gem twitter-bootstrap-rails has some bug.)
Ah, much better question :-).
The twitter-bootstrap-rails gem uses LESS, which is similar to SASS in what it does, but not the same. SASS is the default for Rails, and a good choice. If you want to use SASS, (and based on the error, it appears you are), then use the Bootstrap SASS gem instead, linked here. It may be possible to use both LESS and SASS together, but that seems like a Bad Idea to me.
Check out Ryan Bates' excellent RailsCast which covers using Twitter Bootstrap in Rails. It covers both alternatives. And then fork over the $9 to get Pro access to his continued RailsCast with more details.

Capybara integration with page-objects gem

Is it possible to use the page-object gem and capybara to automate Ruby on Rails testing? When I attempt to access a page object after starting up my test I receive the following error:
Unable to pick a platform for the provided browser (RuntimeError)
This makes sense as I think I'd have to pass the browser instance of capybara to the page-object, not sure if anyone else has tried this before.
There is a gem that lets you use the Page Object pattern with capybara: SitePrism. Find it here: https://github.com/natritmeyer/site_prism
Currently there is no support for capybara but it has been requested a few times. Part of the challenge is that the API was built upon selenium and watir which are much richer than capy and in it would be a very large undertaking to build add that functionality to the page-object gem to make capy behave the same way.
I've thought several times about splitting the page-object gem into a "basic" form that will allow capybara to utilize and an "advanced" form that will add the additional capabilities found in selenium and watir but haven't seen enough demand.
https://github.com/andyw8/capybara-page-object looks like it started existing in the last 8 months or so.

Building a ruby gem for Rails applications

As a Rails developer I feel a bit stupid asking this question but hopefully I will learn something new and someone can put me out of my misery! In my rails applications I use (other peoples) gems all the time, I also use plugins from the community or my own.
I understand the benefits of use gems over plugins as they are version-able, segmented, system wide, easier to manage and share etc etc but I don't really know how to go about making a gem for my rails apps!?
Do you always start with a plugin and convert it to a gem, I've seen the words 'package it as Gem'. Also the gem I'm thinking of building would be no good in a normal ruby program, it's only useful to rails apps. I'm not even sure if the semantics of that make sense, 'RubyGem' that will only work in a rails application!?
I would like to create a gem (if that's what I should use?) for a discrete piece of functionality for my rails apps. It will need to add a database migration, new routes and provide controllers and views or useful view helpers. I'm know I can achieve this via a plug-in but would just like to know how/why to do it as a 'Ruby Gem'?
To avoid the risk of Over-engineering, I usually start with the feature I need directly into the application. Then, as soon as I need to use the same feature into another project, I check whether it is worth to extract it into a plugin or even a separate application providing an API.
Plugins and Gems are often interchangeable. Gems provides several significant advantages in terms of reusability and maintainability.
On the other side, there are some specific known issue. For instance, a Rails app actually can't load rake tasks defined into a plugin packaged as a Gem.
Almost every Rails plugin can be packaged as a Gem.
For instance, take my tabs_on_rails plugin.
You can install it as a Gem specifying the dependency on environment.rb. Or you can use script/plugin install command as you would expect.
If you want to achieve the same result, make sure to follow the standard Gem layout and provide the init.rb initialization script required by Rails.
Also, you might want to create an install.rb and uninstall.rb file to include the post-install and post-uninstall hooks when the plugin is installed as a standard Rails plugin.
Last but not least, if you package a plugin as Gem you can reuse it in non-Rails projects and provide Rails-specific initializations using the init.rb file. Non-Rails applications will simply ignore it.
If you want to make a plugin for Rails, https://peepcode.com/products/rails-2-plugin-patterns gives you a good start. After that, make the plugin into a gem.
To make a gem, this resource http://railscasts.com/episodes/183-gemcutter-jeweler will be helpful.
As of 2013 you'll want to use Bundler and the following tutorials:
#245 New Gem with Bundler -
RailsCasts
Make your own gem - RubyGems
Guides
Take a look at Jeweler. Jeweler gives you a set of rake tasks to make gem versioning and building very easy.

Getting started with rails? Must have gems?

I'm starting work on a project using Rails, but I'm waiting for the 3rd edition of the pragmatic rails book to come out before I purchase a book.
Anyway, my question is a bit more pointed than how do I get started...
What are some of the must have gems that everyone uses?
I need basic authentication, so I have the restful authentication gem, but beyond that, I don't know what I don't know. Is there a run down of this information somewhere? Some basic setup that 99% of the people start with when starting a new rails application?
Thanks in advance.
The gems and plugins that I tend to use on most of my projects are:
Restful Authentication -- For authentication
Will Paginate -- For pagination
Attachment Fu -- For image and file attachments
RedCloth -- For textile rendering
Capistrano -- For deployment
For pagination, will_paginate.
This is very, very subjective because it all depends on what your application does! However, I've just had a look at the Gems I have installed and the one that absolutely does leap out as mandatory is Capistrano.
BTW Restful Authentication is a Rails plugin not a Gem.
HAML is a must have. You'll never think of HTML in the same way again -- No more tag soup.
sudo gem install haml
sudo gem install ZenTest
rspec on rails
How can nobody have mentioned andand yet? It's the best thing since ||=
The only gems you need are:
Rails
Rake
If you "gem install rails" you'll get everything you need for Rails. You only need gems when you need them, so it's not worth worrying about before then.
EDIT: Actually there are a couple more you'll probably need:
mysql - or whatever Ruby database driver you need
mongrel - you don't necessarily need this until production, but it's nice to use in dev/test too
ZenTest - I use this mainly for "autotest" so that my tests run in a console window whenever my source files change
There could be many other gems that help you but we'd need more info from you to know if they're applicable, eg:
Web scraping (hpricot)
CSV (fastercsv)
Amazon S3 support (aws-s3)
Image manipulation (rmagick)
Graphing (gruff) - I use this as a plugin
Role-based security (role_requirement) - This one is a plugin too
mini_magick instead of rmagick.
Might want to keep an eye on: http://rubygems.org/ - you can see some interesting stats there re: most downloaded, most active, etc...
Also interesting and somewhat telling: https://github.com/languages/Ruby
This is a old thread but I thought I'll refine the list with what I believe to be must have gems at this point in time:
RSpec or Shoulda - tools for BDD/testing
factory_girl - fixture replacement
will_paginate - simple pagination
paperclip - image uploading/attachment
CanCan - authorization
Authlogic - authentication
HAML - templating engine

Resources