undefined method `visit’ for # (NoMethodError)

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem
When using Cucumber and Webrat in a ruby on rails 3 application you see the error: undefined method `visit' for # (NoMethodError) and your scenario fails.

Solution
Replace the line:
config.mode = :rails
with the line:
config.mode = :rack
in the Webrat.configure block, in your
app/features/support/env.rb
file.

Adding Webrat, Cucumber and RSpec to a new Rails 3 project

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You would like to start using BDD in a new Ruby on Rails 3 application, and would like to install Webrat, Cucumber and RSpec to your project.

Solution

Follow the steps below (taken from the RSpec Book), for creating a new Rails 3 application and adding the necessary testing frameworks:

  1. Create your new ruby on rails application: rails new my_app
  2. Go to your new application directory: cd my_app
  3. Edit your Gemfile to include the following:
    group :development, :test do
    gem "rspec-rails", ">= 2.0.0"
    gem "cucumber-rails", ">= 0.3.2"
    gem "webrat", ">= 0.7.2"
    end
  4. Use bundler to install all the gems and dependencies: bundle install
  5. Install the rspec files: script/rails generate rspec:install
  6. Install the cucumber files: script/rails generate cucumber:install
  7. Run the following and you shouldn’t be seeing any errors:
    rake db:migrate
    rake db:test:prepare
    rake spec
    rake cucumber

Creating a new git repository in Gitorious

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem
You would like to host a new git repository in Gitorius.

Solution
Assuming that you have created your initial ruby on rails application, and you have git installed, you can follow the steps below:

  1. Create a new account in Gitorious
  2. Copy your public ssh key (usually in ~./ssh) to your new account in Gitorius
  3. Create a new project in Gitorius (ie My Project)
  4. Add a new repository in Gitorius (ie My Git Repository)
  5. On your local development host initialise the git repository in your project’s directory: git init
  6. Add your remote hosting repository: git remote add origin git@gitorious.org:my-project-name/my-git-repo.git
  7. Add your project files: git add .
  8. Do your initial commit: git commit -m "Initial commit"
  9. Push your project to the Gitorious repository: git push origin master