Showing posts with label rspec. Show all posts
Showing posts with label rspec. Show all posts

Monday, May 16, 2011

How to create create RSpec helper and share.

Create RSpec helper method and share in all specs if you need.
*RSpec ver 1.3x

Create helper
module UserHelpers
  def user_helper_method
     #do something
  end
end

describe User
  include UserHelpers
  .
  .
  .
end
Share in all specs
RSpec.configure do |config|
  config.include(UserHelpers)
end

Thursday, April 7, 2011

How to set Custom Rspec Matchers

rspec version is 1.3.x.
create custom_matchers.rb in application's spec directory, railsapp/spec.
custom_matchers.rb
module CustomMatcher
  def matcher_something
    #define custom matcher
  end
end

edit railsapp/spec/spec_helper.rb
.
.
.
require 'spec/rails'
require File.dirname(__FILE__) + "/custom_matchers"
・
・
Spec::Runner.configure do |config|
  .
  .
  config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
  config.include(CustomMatcher)
And matcher_someting is enabled.