Posts mit dem Label rspec werden angezeigt. Alle Posts anzeigen
Posts mit dem Label rspec werden angezeigt. Alle Posts anzeigen

Donnerstag, 13. November 2008

Rspec installation

>sudo gem install ZenTest
>sudo gem install rspec-rails

in application root:
>ruby script/generate rspec

autotest (if it hangs use >RSPEC=true autotest)


rake spec
rake spec:app

rake spec:models
rake spec:controllers
rake spec:views
rake spec:helpers
rake spec:plugins
rake --tasks:plugins

Dienstag, 2. September 2008

Developing Rails Plugins with RSpec

To use RSpec while developing plugins install this rspec generator plugin as follows.

Install RSpec Plugin

script/plugin install git://github.com/pat-maddox/rspec-plugin-generator.git

Create Plugin Framework
script/generate rspec_plugin new_fu


Setup Autotesting
create a file: discover.rb to vendor/plugins/new_fu/lib/autotest/


insert the following at the top of the discover.rb file:
$:.push(File.join(File.dirname(__FILE__), %w[.. .. rspec]))
Autotest.add_discovery do
rspec
end

create a spec.opts file in the plugin/new_fu/spec folder and add the following:

--colour
--format progress
--loadby mtime
--reverse

Set Plugin Location
This avoids naming conflicts with other plugins.
create a directory structure within nuw_fu/lib somthing like this.
your_name/name_or_your_company

Now move the new_fu.rb file into the directory name_of_your_company.

Your new_fu.rb file should now be in
app/vendors/plugins/new_fu/your_name/name_of_your_company/new_fu.rb

Start Autotest for Apllication
Open a terminal window and go to the root of your apllication
first type: rake spec
It should run through and sync the app with your rspec environment
Then type: autotest
The autostest should start and re-run everytime you change a file in your application

Set test environment
open a terminal window - locate the base of your app and type:
export RAILS_ENV=test

Start Autotest for Plugin
Open a terminal window and go to the root of your plugin directory
app/vendor/plugins/new_fu/
and type in autotest
The autostest should start and re-run everytime you change a file in your plugin

Set up Plugin init.rb file.
Locate the init.rb file in vendor/plugins/new_fu
add: include 'your_name/name_of_your_company/new_fu'

Set up Plugin as a module
Open your plugin file
vendor/plugins/new_fu/your_name/name_of_your_company/new_fu.rb
add the following.

.module YourName
....module NameOfYourCompany
.......module NewFu
.
...........def hello_world
..............puts "Hello World"
...........end
.
......end
...end
.end

Then in the new_fu_spec.rb file - located in vendor/plugins/new_fu/spec/ - add the following:

.require File.dirname(__FILE__) + '/spec_helper'
.
.describe YourName::NameOfYourCompany::NewFu, "" do
......include YourName::NameOfYourCompany::NewFu
.
......before do
......end
.
......it "should should say hello world" do
........hello_world
.....end
.
.end

The autotest should have passed on the tests and you should see "hello world" somewhere in the output.

######## To Be Continued.....
Further documentation.
Understanding and building plugins - Part I
Understanding and building plugins - Part II
Creating Plugins Manual
Autotesting while writing Rails Plugins

Samstag, 30. August 2008

RSpec CheatSheet



















>rake -T spec (output of the available rake tasks for rspec)
>ruby script/spec -h (output availble plugin rspec options)
>ruby script/generate (shows the rspec generators that replace the normal rails generators)
(i.e. ruby script/generate rspec_scaffold will show the available options)
>rake doc:plugins (generate the rspec documentation in doc/plugins/rspec-rails/index.html)
>rake spec (sync the development environement with the test environment before running autotest)
>autotest (starts the background testing)

IMPORTANT: Set the test rspec it set up to work in the test environment, so make sure it has been set
Also see extention spec helper methods post

Setup New Rails Project

  1. Create a new project with: >rails name_of_project, then: >cd name_of_project
  2. Optionally if using other database than Sqlite: > rake db:create:all
  3. Install RSpec Plugin & Framework. Refer to the latest instructions.
  4. Run the RSpec generator to create framework: >ruby script/generate rspec
  5. Create latest plugin documents on local drive with: rake doc:plugins. Location of documentation is "name_of_project/doc/plugins/respec-rails/index.html. Open directly in browser with: open -a Firefox doc/plugins/rspec_on_rails/index.html. Or open index.html
  6. Install and run RSpec plugin framework if needed
  7. Create the git repository with a cd to the "name_of_project" directory and then:
>git config --global user.name "your name"
>git config --global user.email "your mail@provider"
>git config --global apply.whitespace nowarn

to check the settings see .gitconfig or: >git config --list

>git init (creates local repository and the .git directory)

create a .gitignore file and add file to ignore
*.log
database.yml
db/schema.*
.DS_Store

>git add . (add all file and contents to firstime checkin)
>git commit -m "first commit"
>git status (check the repos)

see git cheatsheet for more

Setup Rails 2.1 on Mac Leopard

A version of rails and gem is already installed on the mac so we will update and expand on this installation as follows
  1. Get and Install TextMate
  2. Get and Download MacPorts - Leopard (universal). After the download and installation, edit or add to .bash_profile file the following: export PATH="/opt/local/bin:/opt/local/sbin:$PATH" (see here for more details)
  3. Update macports from the command line terminal with: >sudo port selfupdate. NOTE: I had a problem with awk not being found during the installation. This was solved by running the installation again.
  4. Install Git and Svn integration as follows: >sudo port install git-core +doc +svn
  5. Update gems with: >sudo gem update
  6. Install Rspec gem with: > sudo gem install rspec
  7. Install Zentest with: >sudi gem install ZenTest. You don't need to install the gem if you are only using rails. Zentest enables autotesting in the background.
  8. Install Rspec TextMate bundle specifically for rails supporting development: cd to the TextMate Bundles directory, i.e. > cd ~/Library/Appliction\Support/TextMate/Bundles. Then: > git git clone git://github.com/dchelimsky/rspec-tmbundle.git RSpec.tmbundle