Difference between revisions of "IsRSpecAwesomeOrWhat"

From CitconWiki
Jump to navigationJump to search
(rv to Revision as of 00:21, 30 April 2007)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Is RSpec Awesome or What? ==
+
=== Is RSpec Awesome or What? ===
  
 
http://rspec.rubyforge.org/
 
http://rspec.rubyforge.org/
 
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.
 
 
  
 
Bret's example:
 
Bret's example:
Line 71: Line 56:
 
   end
 
   end
 
   specify 'a user can login' do
 
   specify 'a user can login' do
     login('dave', 'secret').should_not Succeed
+
     login('dave', 'secret').should succeed
 
   end
 
   end
 
   specify 'a disallowed user cant login' do
 
   specify 'a disallowed user cant login' do
     login('elisabeth', 'nopassword').should_not Succeed
+
     login('elisabeth', 'nopassword').should_not succeed
 
#    $ie.text.should include('Invalid user/password combination')     
 
#    $ie.text.should include('Invalid user/password combination')     
 
   end
 
   end
Line 82: Line 67:
 
end
 
end
 
</pre>
 
</pre>
 +
 +
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.

Latest revision as of 08:26, 2 April 2008

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.