/
generators_spec.rb
109 lines (83 loc) · 2.97 KB
/
generators_spec.rb
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
99
100
101
102
103
104
105
106
107
108
109
# frozen_string_literal: true
require "simplecov" if ENV["SIMPLECOV"]
require "spec_helper"
require "decidim/gem_manager"
module Decidim
describe Generators do
let(:env) do |example|
if ENV["SIMPLECOV"]
{
"RUBYOPT" => "-rsimplecov #{ENV["RUBYOPT"]}",
"RUBYLIB" => "#{repo_root}/decidim-generators/lib",
"PATH" => "#{repo_root}/decidim-generators/exe:#{ENV["PATH"]}",
"COMMAND_NAME" => example.full_description.tr(" ", "_")
}
else
{}
end
end
let(:result) do
Bundler.with_original_env { GemManager.capture(command, env: env) }
end
# rubocop:disable RSpec/BeforeAfterAll
before(:all) do
Decidim::GemManager.install_all(out: File::NULL)
end
after(:all) do
Decidim::GemManager.uninstall_all(out: File::NULL)
end
# rubocop:enable RSpec/BeforeAfterAll
context "with an application" do
let(:test_app) { "spec/generator_test_app" }
after { FileUtils.rm_rf(test_app) }
shared_examples_for "a new production application" do
it "includes optional plugins commented out in Gemfile" do
expect(result[1]).to be_success, result[0]
expect(File.read("#{test_app}/Gemfile"))
.to match(/^# gem "decidim-initiatives"/)
.and match(/^# gem "decidim-consultations"/)
end
end
shared_examples_for "a new development application" do
it "includes optional plugins uncommented in Gemfile" do
expect(result[1]).to be_success, result[0]
expect(File.read("#{test_app}/Gemfile"))
.to match(/^gem "decidim-initiatives"/)
.and match(/^gem "decidim-consultations"/)
end
end
context "without flags" do
let(:command) { "decidim #{test_app}" }
it_behaves_like "a new production application"
end
context "with --edge flag" do
let(:command) { "decidim --edge #{test_app}" }
it_behaves_like "a new production application"
end
context "with --branch flag" do
let(:command) { "decidim --branch master #{test_app}" }
it_behaves_like "a new production application"
end
context "with --path flag" do
let(:command) { "decidim --path #{repo_root} #{test_app}" }
it_behaves_like "a new production application"
end
context "with a development application" do
let(:command) { "decidim --path #{repo_root} #{test_app} --recreate_db --seed_db --demo" }
it_behaves_like "a new development application"
end
end
context "with a component" do
let(:test_component) { "dummy_component" }
let(:command) { "decidim --component #{test_component}" }
after { FileUtils.rm_rf("decidim-module-#{test_component}") }
it "suceeeds" do
expect(result[1]).to be_success, result[0]
end
end
private
def repo_root
File.expand_path(File.join("..", ".."), __dir__)
end
end
end