Skip to content

Commit

Permalink
Added rspec infrastructure.
Browse files Browse the repository at this point in the history
  • Loading branch information
romul committed Oct 28, 2010
1 parent cf6955f commit 111bed4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
41 changes: 40 additions & 1 deletion Rakefile
Expand Up @@ -26,4 +26,43 @@ RSpec::Core::RakeTask.new
require 'cucumber/rake/task'
Cucumber::Rake::Task.new do |t|
t.cucumber_opts = %w{--format pretty}
end
end

desc "Regenerates a rails 3 app for testing"
task :test_app do
SPREE_PATH = ENV['SPREE_PATH']
raise "SPREE_PATH should be specified" unless SPREE_PATH
require File.join(SPREE_PATH, 'lib/generators/spree/test_app_generator')
class AuthTestAppGenerator < Spree::Generators::TestAppGenerator
def tweak_gemfile
append_file 'Gemfile' do
<<-gems
gem 'spree_core', :path => '#{File.join(SPREE_PATH, 'core')}'
gem 'spree_auth', :path => '#{File.join(SPREE_PATH, 'auth')}'
gem 'spree_store_credits', :path => '#{File.join(SPREE_PATH, '..', 'store_credits')}'
gem 'spree_email_to_friend', :path => '#{File.join(SPREE_PATH, '..', 'spree-email-to-friend')}'
gem 'spree_affiliate', :path => '../..'
gems
end
end

def install_gems
system("cd spec/test_app && rake spree_core:install")
system("cd spec/test_app && rake spree_auth:install")
generate 'spree_store_credits:install -f'
generate 'spree_affiliate:install -f'
end

def migrate_db
run_migrations
end
end
AuthTestAppGenerator.start
end

namespace :test_app do
desc 'Rebuild test and cucumber databases'
task :rebuild_dbs do
system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
end
end
8 changes: 8 additions & 0 deletions spec/models/user_spec.rb
@@ -0,0 +1,8 @@
require 'spec_helper'

describe User do
let(:user) { User.new(:email => "foo@bar.com", :password => "secret", :password_confirmation => "secret") }
it "should have ref id" do
user.ref_id.should_not == nil
end
end
28 changes: 28 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,28 @@
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../test_app/config/environment", __FILE__)
require 'rspec/rails'
require 'fabrication'

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec

config.fixture_path = "#{::Rails.root}/spec/fixtures"

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, comment the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end

0 comments on commit 111bed4

Please sign in to comment.