Skip to content

Commit

Permalink
Created rspec infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
romul committed Oct 13, 2010
1 parent 8257f5a commit 98044e5
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
tmp
nbproject
*.swp
spec/test_app
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ SpreeGiftCards
Introduction goes here.


Example
To run specs
=======

Example goes here.
1. rake test_app
1. rails g spree_gift_cards:install -f
1. rake spec


Copyright (c) 2010 [name of extension creator], released under the New BSD License
Copyright (c) 2010 Roman Smirnov, released under the New BSD License
39 changes: 38 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,41 @@ 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_gift_cards', :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'
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
1 change: 1 addition & 0 deletions lib/generators/spree_gift_cards/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def copy_migrations
end

def run_db_seeds
system("cd #{Rails.root} && rake db:migrate RAILS_ENV=#{Rails.env}")
seed_file = File.join(File.expand_path("../../../../db", __FILE__), "seeds.rb")
load(seed_file) if File.exist?(seed_file)
end
Expand Down
16 changes: 16 additions & 0 deletions spec/models/gift_card_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe GiftCard do
let(:gift_card) { GiftCard.new }

context "Store credits." do
before do
end

it "Test" do
1.should == 1
end


end
end
28 changes: 28 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.

0 comments on commit 98044e5

Please sign in to comment.