IsRSpecAwesomeOrWhat

From CitconWiki
Jump to navigationJump to search

Is RSpec Awesome or What?

http://rspec.rubyforge.org/

Bret's example:

require 'spec'
require 'watir'
require 'watir/contrib/ie-new-process'

def login user, password
    $ie = $ie || Watir::IE.new
    $ie.goto 'http://localhost:3000/login/login'
    $ie.text.should include('Administer Bookshelf')
    $ie.text_field(:id, 'user_name').set user
    $ie.text_field(:id, 'user_password').set password
    $ie.button(:value, ' LOGIN ').click
    LoginResult.new user, password
end

class LoginResult
  def initialize user, password
    @user = user; @password = password
  end
  def success?
    $ie.text.include?('Depot Store Status')    
  end
  def failure_message
    "Unable to login using #{@user} and #{@password}"
  end
  def negative_failure_message
    "Were able to login, but we shouldn't have been"  
  end
end

def succeed
  Succeed
end

class Succeed
  def Succeed.matches? actual
    @actual = actual
    @actual.success?
  end
  def Succeed.failure_message
    @actual.failure_message
  end
  def Succeed.negative_failure_message
    @actual.negative_failure_message
  end
end

context 'on the login page' do
  setup do
  end
  specify 'a user can login' do
    login('dave', 'secret').should succeed
  end
  specify 'a disallowed user cant login' do
    login('elisabeth', 'nopassword').should_not succeed
#    $ie.text.should include('Invalid user/password combination')    
  end
  teardown do
    # at_exit {$ie.kill}
  end
end

Elisabeth: on a project using TestUnit and RSpec. Wish we just cut over because it is tempting to stay in TestUnit which is more familiar.

IDE support for RSpec

Refactoring support for Ruby Eclipse Plug-in

Lots of harassment from the Mac users.

Hamcrest library examples

Should...When... in JUnit

Embedding expectations and failure messages into the LoginResult.