Skip to content
Arjen Oosterkamp edited this page Apr 8, 2014 · 1 revision

This page describes setting up Alfred.

Installation

  1. Add gem 'alfred_rails' to your Gemfile.
  2. Run bundle install.

Configure Alfred

If you need to stub anything, or you use Devise/FactoryGirl you can include their helpers.

# spec/alfred_helper.rb

Alfred.configure do |config|
  ## Includes
  config.include FactoryGirl::Syntax::Methods
  config.include Devise::TestHelpers

  ## Setup
  config.setup do
    Apartment::Database.stub(:create).and_return(true)
  end
  
  ## Mocking framework
  config.mock_with :rspec
  
  ## Fixture path
  config.fixture_path 'spec/javascripts/fixtures'
end

Define your scenarios

# spec/alfreds/api/v1/posts_controller.rb

Alfred.define do
  setup do
    sign_in :user, create(:user)
  end

  controller Api::V1::PostsController do
    scenario 'update post by manager' do
      setup do
        create(:post, :title => 'Alfred is awesome', :body => 'It saves me time')
      end

      patch :update, {
        :format => :json,
        :id     => 1,
        :post   => {
          :title => 'Alfred rocks!'
        }
      }
    end
  end
end

Run alfred in your console. This generates all fixtures.

Clone this wiki locally