configuration.rb

Path: lib/rackbox/spec/configuration.rb
Last Update: Sun Feb 08 14:57:38 -0700 2009

Extend the RSpec configuration class with a use_blackbox option

To add blackbox testing to a Rails app, in your spec_helper.rb

  require 'rackbox'

  Spec::Runner.configure do |config|
    config.use_blackbox = true
  end

Required files

webrat   webrat/core/matchers  

Methods

Included Modules

RackBox::SpecHelpers RackBox::Matchers ActionController::UrlWriter Webrat::HaveTagMatcher RackBox::Matchers

Public Instance methods

Adds blackbox testing to your Rails application using RackBox.

To use, put your ‘blackbox’ specs into the spec/blackbox directory, eg. spec/blackbox/login_spec.rb

In these specs, the RackBox::SpecHelpers#req method will be available to you

[Source]

    # File lib/rackbox/spec/configuration.rb, line 26
26:     def use_blackbox= bool
27:       if bool == true
28:         
29:         before(:all, :type => :blackbox) do
30:           self.class.instance_eval {
31:             # include our own helpers, eg. RackBox::SpecHelpers#req
32:             include RackBox::SpecHelpers
33:             include RackBox::Matchers
34: 
35:             # include generated url methods, eg. login_path.
36:             # default_url_options needs to have a host set for the Urls to work
37:             if defined?ActionController::UrlWriter
38:               include ActionController::UrlWriter
39:               default_url_options[:host] = 'example.com'
40:             end
41: 
42:             # if we're not in a Rails app, let's try to load matchers from Webrat
43:             unless defined?RAILS_ENV
44:               begin
45:                 require 'webrat'
46:                 require 'webrat/core/matchers'
47:                 include Webrat::HaveTagMatcher
48:               rescue LoadError
49:                 puts "Webrat not available.  have_tag & other matchers won't be available.  to install, sudo gem install webrat"
50:               end
51:             end
52: 
53:             attr_accessor :rackbox_request
54:           }
55:         end
56: 
57:         before(:each, :type => :blackbox) do
58: 
59:           # i'm sure there's a better way to write this!
60:           #
61:           # i believe metaid would write this as:
62:           #   metaclass.class_eval do ... end
63:           #
64:           (class << self; self; end).class_eval do 
65:             include RackBox::Matchers
66:           end
67: 
68:           @rackbox_request = Rack::MockRequest.new RackBox.app
69:         end
70: 
71:       end
72:     end

[Validate]