-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRakefile
98 lines (80 loc) · 2.38 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
ENV['LIB_NAME'] = 'klarna_gateway'
require "dotenv"
Dotenv.load
require "bundler/gem_tasks"
Bundler::GemHelper.install_tasks
require "awesome_print"
require "rspec/core/rake_task"
require 'spree/testing_support/common_rake'
dummy_rake_file = File.expand_path("../spec/dummy/Rakefile", __FILE__)
if File.exist?(dummy_rake_file)
APP_RAKEFILE = dummy_rake_file
load 'rails/tasks/engine.rake'
Rails.application.load_tasks
end
module KlarnaOutputHelper
def self.pe(command)
ap "Executing: " << command
command = "cd spec/dummy && RAILS_ENV=test " << command
system command
end
end
namespace :klarna_gateway do
namespace :spec do
desc 'Generates a dummy app for testing'
task :create_dummy_app do
Rake::Task['common:test_app'].invoke
end
end
namespace :bdd do
desc "Prepares database for BDD tests"
task :prepare do
if Dir["spec/dummy"].empty?
Rake::Task['klarna_gateway:spec:create_dummy_app'].invoke
Dir.chdir("../../")
end
KlarnaOutputHelper.pe "bundle exec rake db:drop db:create"
KlarnaOutputHelper.pe "bundle exec rake railties:install:migrations"
KlarnaOutputHelper.pe "bundle exec rake db:migrate"
KlarnaOutputHelper.pe "[email protected] ADMIN_PASSWORD=test123 bundle exec rake db:seed"
KlarnaOutputHelper.pe "bundle exec rake spree_sample:load"
end
desc "Run BDD tests"
task :run do
Rake::Task['klarna_gateway:bdd:prepare'].invoke
Rake::Task["spec"].clear
begin
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = "--tag bdd"
end
rescue LoadError
# no rspec available
end
Rake::Task["spec"].invoke
end
end
namespace :tdd do
desc "Prepare db for TDD tests"
task :prepare do
if Dir["spec/dummy"].empty?
Rake::Task['klarna_gateway:spec:create_dummy_app'].invoke
Dir.chdir("../../")
end
KlarnaOutputHelper.pe "bundle exec rake db:drop db:create db:schema:load"
end
desc "Run TDD tests"
task :run do
Rake::Task['klarna_gateway:tdd:prepare'].invoke
Rake::Task["spec"].clear
begin
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = "--tag ~bdd"
end
rescue LoadError
# no rspec available
end
Rake::Task["spec"].invoke
end
end
end
task :default, 'klarna_gateway:tdd:run'