diff --git a/.gitignore b/.gitignore index dbe7f07..39a875e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ tmp nbproject *.swp -spec/test_app -*.tmproj \ No newline at end of file +spec/dummy +*.tmproj +Gemfile.lock diff --git a/Gemfile b/Gemfile index fef476b..caa8242 100644 --- a/Gemfile +++ b/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 diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 87dd97c..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,8 +0,0 @@ -GEM - remote: http://rubygems.org/ - specs: - -PLATFORMS - ruby - -DEPENDENCIES diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..2517982 --- /dev/null +++ b/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 + diff --git a/Rakefile b/Rakefile index cfc1eb1..cfc0970 100644 --- a/Rakefile +++ b/Rakefile @@ -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 @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ad92fa0..93c5af0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,28 +1,16 @@ -require File.expand_path("../factories", __FILE__) +# Configure Rails Environment +ENV["RAILS_ENV"] = "test" +require File.expand_path("../dummy/config/environment.rb", __FILE__) - -######################################################################## -# NOTE: The rest of file is the same as spree/core/spec/spec_helper.rb # -######################################################################## - - - - - - - -# 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 @@ -34,28 +22,20 @@ RSpec.configure do |config| # 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") +require File.expand_path("../factories", __FILE__) -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 - -# 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 \ No newline at end of file diff --git a/spree_digital.gemspec b/spree_digital.gemspec index 8673dab..c4118bf 100644 --- a/spree_digital.gemspec +++ b/spree_digital.gemspec @@ -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 \ No newline at end of file