27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Application setup<br />

This command installs not only the rspec-rails, cucumber, and capybara gems but<br />

also their dependencies (and so on)! How great is that? You’re just getting started.<br />

The bundle install --binstubs command also creates a Gemfile.lockfile that contains<br />

a list of the gems and their relative versions. Once Gemfile.lock is created,<br />

whenever you run bundle install, Bundler reads this file rather than Gemfile to work<br />

out the dependencies of the application and installs from it. You commit this file to<br />

your repository so that when other people work on your project and run bundle<br />

install, they get exactly the same versions that you have.<br />

Next, you want to generate the skeleton for Cucumber. A generator can generate<br />

either static or dynamic content, depending on the generator. For the Cucumber skeleton<br />

generator, it’s set content. To run this generator, you use the rails command<br />

rails generate cucumber:install<br />

or simply<br />

rails g cucumber:install<br />

Rails doesn’t mind if you use generate or g: it’s all the same to Rails.<br />

Let’s not mind too much about all the files it has generated at the moment; they’re<br />

explained in time. With the Cucumber skeleton now generated, you have a base on<br />

which to begin writing your features.<br />

While you’re generating things, you may as well run the RSpec generator too:<br />

rails generate rspec:install<br />

With this generated code in place, you should make a commit so you have another<br />

base to roll back to if anything goes wrong:<br />

git add .<br />

git commit -m "Ran the cucumber and rspec generators"<br />

git push<br />

3.1.4 Database configuration<br />

By default, Rails uses a database system called SQLite3, which stores each environment’s<br />

database in separate files inside the db directory. SQLite3 is the default database<br />

system because it’s the easiest to set up. Out of the box, Rails also supports the<br />

MySQL and PostgreSQL databases, with gems available that can provide functionality<br />

for connecting to other database systems such as Oracle.<br />

If you want to change which database your application connects to, you can open<br />

config/database.yml (development configuration shown in the following listing) and<br />

alter the settings to the new database system.<br />

Listing 3.6 config/database.yml<br />

development:<br />

adapter: sqlite3<br />

database: db/development.sqlite3<br />

pool: 5<br />

timeout: 5000<br />

53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!