Friday, April 9, 2010

RSpec

The Rspec nomenclature has progressed beyond xUnit.
Test => Example
Marick suggests we use the term 'example' instead of 'test' to emphasise the design and documentation aspect of the artifact.
Assertions => Expectations
Assertions is too strong a word for examples when we are describing what should happen.
require 'watir'
require 'spec'

Watir::Browser.default = 'firefox'

describe "a simple demonstration of watir and trad RSpec" do
  before(:each) do
    @browser ||= Watir::Browser.new
    @browser.goto("http://cukes.info/")  end

  describe "that we have hit a valid URL" do
    it "should not return an invalid error message" do
      @browser.text.should_not include('The requested URL could not be retrieved')
    end
   end

  describe "the contents of the cukes page" do # the describe() is an example group
    it "should include aidy's name" do # the it() represents the detail that will be expressed in the code within the block
      @browser.text.should include('Aidy Lewis')
    end

    it "should not include the great Nietchzche's name" do
      @browser.text.should_not include('Frederick Nietchzche')
    end
  end

 after(:each) do
   @browser.close unless @browser.nil?
 end
end


# run with
# spec -c filename.rb

No comments:

Post a Comment