Skip to content

Commit

Permalink
Updating Rakefile, Gemfile, etc for Spree 1.0 testing compatibilty
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveitaly committed Mar 30, 2012
1 parent 7f729bd commit 62082f5
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 127 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Expand Up @@ -7,5 +7,6 @@
tmp
nbproject
*.swp
spec/test_app
*.tmproj
spec/dummy
*.tmproj
Gemfile.lock
47 changes: 14 additions & 33 deletions Gemfile
@@ -1,35 +1,16 @@
source 'http://rubygems.org'

#gem 'spree_core', :path => '../spree/core'
#gem 'spree_digital', :path => 'spree_digital'
#gem "sqlite3-ruby"
#
#group :test do
# gem 'rspec-rails', '= 2.5.0'
# gem 'factory_girl', '= 1.3.3'
# gem 'factory_girl_rails', '= 1.0.1'
# gem 'rcov'
# gem 'shoulda'
# gem 'faker'
# if RUBY_VERSION < "1.9"
# gem "ruby-debug"
# else
# gem "ruby-debug19"
# end
#end
#
#group :cucumber do
# gem 'cucumber-rails'
# gem 'database_cleaner', '= 0.6.7.RC'
# gem 'nokogiri'
# gem 'capybara', '= 0.4.1.2'
# gem 'factory_girl', '= 1.3.3'
# gem 'factory_girl_rails', '= 1.0.1'
# gem 'faker'
# gem 'launchy'
# if RUBY_VERSION < "1.9"
# gem "ruby-debug"
# else
# gem "ruby-debug19"
# end
#end
group :test do
# without ffaker in test it wont init
# https://github.com/spree/spree/pull/833
gem 'ffaker'
gem 'shoulda-matchers'
gem 'guard-rspec'

if RUBY_PLATFORM.downcase.include? "darwin"
gem 'rb-fsevent'
gem 'growl'
end
end

gemspec
8 changes: 0 additions & 8 deletions Gemfile.lock

This file was deleted.

18 changes: 18 additions & 0 deletions Guardfile
@@ -0,0 +1,18 @@


guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end

64 changes: 13 additions & 51 deletions Rakefile
Expand Up @@ -3,31 +3,15 @@ require 'rake/testtask'
require 'rake/packagetask'
require 'rubygems/package_task'
require 'rspec/core/rake_task'
require 'cucumber/rake/task'
require 'spree_core/testing_support/common_rake'
require 'spree/core/testing_support/common_rake'

gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
if File.exists?(gemfile) && (%w(spec cucumber).include?(ARGV.first.to_s) || ARGV.size == 0)
require 'bundler'
ENV['BUNDLE_GEMFILE'] = gemfile
Bundler.setup
RSpec::Core::RakeTask.new

require 'rspec'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new

require 'cucumber/rake/task'
Cucumber::Rake::Task.new do |t|
t.cucumber_opts = %w{--format progress}
end
end

desc "Default Task"
task :default => [:spec, :cucumber ]
task :default => [:spec]

spec = eval(File.read('spree_digital.gemspec'))

Rake::GemPackageTask.new(spec) do |p|
Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end

Expand All @@ -38,40 +22,18 @@ task :release => :package do
Rake::Task['gem:push'].invoke
end

desc "Default Task"
task :default => [ :spec ]

desc "Regenerates a rails 3 app for testing"
task :test_app do
require '../spree/lib/generators/spree/test_app_generator'
class SpreeDigitalTestAppGenerator < Spree::Generators::TestAppGenerator

def install_gems
inside "test_app" do
run 'rake spree_core:install'
run 'rake spree_digital:install'
end
ENV['LIB_NAME'] = 'spree_digital'

require File.join `bundle show spree_core`.chomp, 'lib/generators/spree/dummy/dummy_generator.rb'
Spree::DummyGenerator.class_eval do
def test_dummy_add_digital
# pulled from: http://jumph4x.net/post/20067515804/testing-spree-1-0-x-extensions-w-other-extension
puts "Installing #{ENV['LIB_NAME']} migrations [required for testing]"
directory File.join(`bundle show #{ENV['LIB_NAME']}`.chomp, 'db', 'migrate'), File.join(dummy_path, 'db')
end

def migrate_db
run_migrations
end

protected
def full_path_for_local_gems
<<-gems
gem 'spree_core', :path => \'#{File.join(File.dirname(__FILE__), "../spree/", "core")}\'
gem 'spree_digital', :path => \'#{File.dirname(__FILE__)}\'
gems
end

end
SpreeDigitalTestAppGenerator.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
Rake::Task['common:test_app'].invoke
end
46 changes: 13 additions & 33 deletions spec/spec_helper.rb
@@ -1,28 +1,16 @@
require File.expand_path("../factories", __FILE__)



########################################################################
# NOTE: The rest of file is the same as spree/core/spec/spec_helper.rb #
########################################################################


# Configure Rails Environment
ENV["RAILS_ENV"] = "test"

require File.expand_path("../dummy/config/environment.rb", __FILE__)




# 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'

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

require 'spree_core/testing_support/factories'
# Requires factories defined in spree_core
require 'spree/core/testing_support/factories'

RSpec.configure do |config|
# == Mock Framework
Expand All @@ -34,28 +22,20 @@
# config.mock_with :rr
config.mock_with :rspec

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

#config.include Devise::TestHelpers, :type => :controller
# 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
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end

@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")

PAYMENT_STATES = Payment.state_machine.states.keys unless defined? PAYMENT_STATES
SHIPMENT_STATES = Shipment.state_machine.states.keys unless defined? SHIPMENT_STATES
ORDER_STATES = Order.state_machine.states.keys unless defined? ORDER_STATES
require File.expand_path("../factories", __FILE__)

# Usage:
#
# context "factory" do
# it { should have_valid_factory(:address) }
# end
# not sure if this really adds anything, but this existed in the intial version of the spree_digital rspec testing
RSpec::Matchers.define :have_valid_factory do |factory_name|
match do |model|
Factory(factory_name).new_record?.should be_false
end
end
end
8 changes: 8 additions & 0 deletions spree_digital.gemspec
Expand Up @@ -12,4 +12,12 @@ Gem::Specification.new do |s|
s.requirements << 'none'
s.required_ruby_version = '>= 1.8.7'
s.add_dependency('spree_core', '~> 1.0.0')

# test suite
s.add_development_dependency 'shoulda-matchers'
s.add_development_dependency 'capybara'
s.add_development_dependency 'factory_girl'
s.add_development_dependency 'ffaker'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'sqlite3'
end

0 comments on commit 62082f5

Please sign in to comment.