fedux_org-stdlib 0.7.19 → 0.7.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9516f8871b827a5de5b69fc4595149163da19a4d
4
- data.tar.gz: ccfee460a2303ba9052aafc4378258d307de5c50
3
+ metadata.gz: ff269d3997e33745be195a1f065d0245fa3990fc
4
+ data.tar.gz: 43dc8d4414f98613161f245835f7f5a10516126f
5
5
  SHA512:
6
- metadata.gz: 4daaf8e7379496dea493224f12491c6898cd53aef9c6b7476dfafc263f15a4ac478ab265681244d2e5b3afa9741826f26d7e6c4aabc2845565d22675a386dec9
7
- data.tar.gz: 4d0ce03fbe1e1a0a2b512376dc4a8e69f73b161b39bf584340b7bdacec74b67ae84eaa7e458ea7d9bf78c97ed9a1989a35a641cb8457f4419ce9d8a097affd64
6
+ metadata.gz: df8ac0a49c961608aef74e34290d24e650fe5cabdb8c223fa3d2db6c1da33124fe3d7394f62622bda7c167431200b4a03de7a22d16b47f8a1f6c2796d4449723
7
+ data.tar.gz: d84f598ede35f0800ef1b2e9ced14ba5e7da8799c0c41114da8c2314a720aa2ce11009358ed15b2c125c7b473321f42dcf436e925c46bdab8c1613dc9ce3916e
data/Gemfile CHANGED
@@ -16,7 +16,7 @@ group :development, :test do
16
16
  gem 'byebug'
17
17
  end
18
18
 
19
- gem 'aruba', require: false
19
+ gem 'aruba', '>= 0.6.1', require: false
20
20
  gem 'awesome_print', require: 'ap'
21
21
  gem 'bundler', '>= 1.3', require: false
22
22
  gem 'coveralls', require: false
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fedux_org-stdlib (0.7.18)
4
+ fedux_org-stdlib (0.7.19)
5
5
  activesupport
6
6
 
7
7
  PATH
@@ -157,7 +157,7 @@ PLATFORMS
157
157
  ruby
158
158
 
159
159
  DEPENDENCIES
160
- aruba
160
+ aruba (>= 0.6.1)
161
161
  awesome_print
162
162
  bundler (>= 1.3)
163
163
  byebug
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+ require 'fedux_org_stdlib/fixtures_management/fixtures_manager'
3
+ require 'fedux_org_stdlib/fixtures_management/fixture'
4
+ require 'fedux_org_stdlib/fixtures_management/no_fixture'
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ require 'fedux_org_stdlib/roles/comparable_by_name'
3
+
4
+ module FeduxOrgStdlib
5
+ module FixturesManagement
6
+ # Fixture
7
+ class Fixture
8
+ include Roles::ComparableByName
9
+
10
+ private
11
+
12
+ attr_reader :type
13
+
14
+ public
15
+
16
+ attr_reader :name, :path
17
+
18
+ def initialize(path)
19
+ @path = Pathname.new(path)
20
+ end
21
+
22
+ # Name of fixture
23
+ def name
24
+ path.basename.to_s.to_sym
25
+ end
26
+
27
+ # Is of type?
28
+ #
29
+ # @return [TrueClass,FalseClass]
30
+ # The result of test
31
+ def type?(t)
32
+ type == t
33
+ end
34
+
35
+ private
36
+
37
+ def type
38
+ if path.end_with? '-plugin'
39
+ :plugin
40
+ else
41
+ :app
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ module FeduxOrgStdlib
3
+ module FixturesManagement
4
+ # Fixture manager
5
+ class FixturesManager
6
+ private
7
+
8
+ attr_reader :fixtures, :creator, :null_klass
9
+
10
+ public
11
+
12
+ def initialize(creator: Fixture, null_klass: NoFixture)
13
+ @fixtures = Set.new
14
+ @creator = creator
15
+ @null_klass = null_klass
16
+ end
17
+
18
+ # Load fixtures found at path
19
+ def load_fixtures(path)
20
+ path = Pathname.new(path)
21
+
22
+ path.entries.each do |f|
23
+ next if f.to_s[/^\.\.?/]
24
+
25
+ add f.expand_path(path)
26
+ end
27
+ end
28
+
29
+ # Add fixture
30
+ def add(path)
31
+ fixtures << creator.new(path)
32
+ end
33
+
34
+ # Find fixture
35
+ def find(name)
36
+ name = name.to_sym
37
+
38
+ fixtures.find(null_klass.new(name)) { |f| f.name == name }
39
+ end
40
+
41
+ # String representation
42
+ def to_s
43
+ data = frontend_components.sort.reduce([]) { |a, e| a << { name: e.name, path: e.path } }
44
+ List.new(data).to_s
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ module FeduxOrgStdlib
3
+ module FixturesManagement
4
+ # Placeholder when no associated fixture found, displays warning
5
+ class NoFixture
6
+ private
7
+
8
+ attr_reader :name
9
+
10
+ public
11
+
12
+ def initialize(name)
13
+ @name = name
14
+ end
15
+
16
+ # Is not an existing plugin
17
+ def blank?
18
+ true
19
+ end
20
+
21
+ def method_missing(*_args)
22
+ warn "Warning: The fixture '#{name}' was not found!"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -2,7 +2,7 @@
2
2
  require 'fedux_org_stdlib/require_files'
3
3
  require_library %w{ command_exec }
4
4
 
5
- require 'fedux_org_stdlib/logging/logger'
5
+ require 'fedux_org_stdlib/project/logger'
6
6
 
7
7
  module FeduxOrgStdlib
8
8
  module Project
@@ -5,8 +5,7 @@ module FeduxOrgStdlib
5
5
 
6
6
  private
7
7
 
8
- attr_reader :main_file,
9
- :additional_files
8
+ attr_reader :main_file, :additional_files
10
9
 
11
10
  public
12
11
 
@@ -17,7 +16,7 @@ module FeduxOrgStdlib
17
16
  # @param [Array] additional_files
18
17
  # Additional files containing information about project plan
19
18
  def initialize(
20
- main_file: File.join(Dir.getwd, 'plan.tjp'),
19
+ main_file: File.expand_path('plan.tjp'),
21
20
  additional_files: []
22
21
  )
23
22
  @main_file = main_file
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require 'fedux_org_stdlib/version_management/rubygem_version_file'
3
- require 'fedux_org_stdlib/versionable'
3
+ require 'fedux_org_stdlib/roles/versionable'
4
4
 
5
5
  module FeduxOrgStdlib
6
6
  module Rake
@@ -26,7 +26,7 @@ module FeduxOrgStdlib
26
26
  #
27
27
  # @see Rakefile
28
28
  class VersionBumpTask < Task
29
- include Versionable
29
+ include Roles::Versionable
30
30
 
31
31
  # @private
32
32
  def bump_version(type)
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'fedux_org_stdlib/versionable'
3
+ require 'fedux_org_stdlib/roles/versionable'
4
4
  require 'fedux_org_stdlib/rake/shell_task'
5
5
 
6
6
  task = FeduxOrgStdlib::Rake::ShellTask.new(
@@ -8,4 +8,4 @@ task = FeduxOrgStdlib::Rake::ShellTask.new(
8
8
  description: 'Restore version file from repository',
9
9
  command: "git checkout <%= version_file %>"
10
10
  )
11
- task.include FeduxOrgStdlib::Versionable
11
+ task.include FeduxOrgStdlib::Roles::Versionable
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require 'fedux_org_stdlib/versionable'
2
+ require 'fedux_org_stdlib/roles/versionable'
3
3
  require 'fedux_org_stdlib/rake/task'
4
4
 
5
5
  task = FeduxOrgStdlib::Rake::Task.new(
@@ -8,5 +8,5 @@ task = FeduxOrgStdlib::Rake::Task.new(
8
8
  ) do |t|
9
9
  $stderr.puts FeduxOrgStdlib::VersionManagement::RubygemVersionFile.read(version_file).version
10
10
  end
11
- task.include FeduxOrgStdlib::Versionable
11
+ task.include FeduxOrgStdlib::Roles::Versionable
12
12
 
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ module FeduxOrgStdlib
3
+ module Roles
4
+ # Included if class can be compared by name
5
+ module ComparableByName
6
+ include Comparable
7
+
8
+ # @private
9
+ def hash
10
+ name.hash
11
+ end
12
+
13
+ # @private
14
+ def eql?(other)
15
+ name.eql? other.name
16
+ end
17
+
18
+ # @private
19
+ def <=>(other)
20
+ name <=> other.name
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ require 'fedux_org_stdlib/rake/exceptions'
3
+
4
+ module FeduxOrgStdlib
5
+ module Roles
6
+ module Versionable
7
+ def version_file(working_directory = Dir.getwd)
8
+ paths = []
9
+ paths << File.join(working_directory, 'lib', '**', 'version.rb')
10
+
11
+ file = Dir.glob(paths.shift).first while !paths.blank? and file.blank?
12
+
13
+ raise FeduxOrgStdlib::Rake::Exceptions::VersionFileNotFound, JSON.dump(message: 'Cannot find version file') unless file
14
+
15
+ file
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # FeduxOrgStdlib
3
3
  module FeduxOrgStdlib
4
- VERSION = '0.7.19'
4
+ VERSION = '0.7.20'
5
5
  end
@@ -6,7 +6,7 @@ RSpec.describe AppConfig do
6
6
 
7
7
  context 'options' do
8
8
  it 'creates readers and writers' do
9
- with_environment 'HOME' => working_directory do
9
+ with_env 'HOME' => absolute_path('.') do
10
10
  config_klass = Class.new(AppConfig) do
11
11
  option :opt1, nil
12
12
 
@@ -28,7 +28,7 @@ RSpec.describe AppConfig do
28
28
  end
29
29
 
30
30
  it 'creates readers' do
31
- with_environment 'HOME' => working_directory do
31
+ with_env 'HOME' => absolute_path('.') do
32
32
  config_klass = Class.new(AppConfig) do
33
33
  option_reader :opt1, nil
34
34
 
@@ -53,7 +53,7 @@ RSpec.describe AppConfig do
53
53
  end
54
54
 
55
55
  it 'checks for reserved key words' do
56
- with_environment 'HOME' => working_directory do
56
+ with_env 'HOME' => absolute_path('.') do
57
57
  expect do
58
58
  Class.new(AppConfig) do
59
59
  option_reader :_config_file, nil
@@ -73,7 +73,7 @@ RSpec.describe AppConfig do
73
73
 
74
74
  context '#lock' do
75
75
  it 'raises error if config is locked and one tries to modify a config option' do
76
- with_environment 'HOME' => working_directory do
76
+ with_env 'HOME' => absolute_path('.') do
77
77
  config_klass = Class.new(AppConfig) do
78
78
  option :opt1, nil
79
79
 
@@ -95,7 +95,7 @@ RSpec.describe AppConfig do
95
95
 
96
96
  context '#preferred_configuration_file' do
97
97
  it 'has a default configuration file which is the preferred place to store the configuration' do
98
- with_environment 'HOME' => working_directory do
98
+ with_env 'HOME' => absolute_path('.') do
99
99
  config_klass = Class.new(AppConfig) do
100
100
 
101
101
  def _class_name
@@ -113,7 +113,7 @@ RSpec.describe AppConfig do
113
113
  end
114
114
 
115
115
  it 'works with nested module names' do
116
- with_environment 'HOME' => working_directory do
116
+ with_env 'HOME' => absolute_path('.') do
117
117
  config_klass = Class.new(AppConfig) do
118
118
 
119
119
  def _class_name
@@ -134,8 +134,8 @@ RSpec.describe AppConfig do
134
134
  context 'config files' do
135
135
 
136
136
  it 'looks at ~/.test.yaml' do
137
- with_environment 'HOME' => working_directory do
138
- create_file '.tests.yaml', <<-EOS.strip_heredoc
137
+ with_env 'HOME' => absolute_path('.') do
138
+ write_file '.tests.yaml', <<-EOS.strip_heredoc
139
139
  ---
140
140
  opt1: hello world
141
141
  EOS
@@ -158,8 +158,8 @@ RSpec.describe AppConfig do
158
158
  end
159
159
 
160
160
  it 'looks at ~/.config/my_application/tests.yaml' do
161
- with_environment 'HOME' => working_directory do
162
- create_file '.config/my_application/tests.yaml', <<-EOS.strip_heredoc
161
+ with_env 'HOME' => absolute_path('.') do
162
+ write_file '.config/my_application/tests.yaml', <<-EOS.strip_heredoc
163
163
  ---
164
164
  opt1: hello world
165
165
  EOS
@@ -182,8 +182,8 @@ RSpec.describe AppConfig do
182
182
  end
183
183
 
184
184
  it 'looks at ~/.my_application/tests.yaml' do
185
- with_environment 'HOME' => working_directory do
186
- create_file '.my_application/tests.yaml', <<-EOS.strip_heredoc
185
+ with_env 'HOME' => absolute_path('.') do
186
+ write_file '.my_application/tests.yaml', <<-EOS.strip_heredoc
187
187
  ---
188
188
  opt1: hello world
189
189
  EOS
@@ -206,8 +206,8 @@ RSpec.describe AppConfig do
206
206
  end
207
207
 
208
208
  it 'looks at ~/.tests.yaml' do
209
- with_environment 'HOME' => working_directory do
210
- create_file '.tests.yaml', <<-EOS.strip_heredoc
209
+ with_env 'HOME' => absolute_path('.') do
210
+ write_file '.tests.yaml', <<-EOS.strip_heredoc
211
211
  ---
212
212
  opt1: hello world
213
213
  EOS
@@ -230,8 +230,8 @@ RSpec.describe AppConfig do
230
230
  end
231
231
 
232
232
  it 'looks at ~/.testsrc' do
233
- with_environment 'HOME' => working_directory do
234
- create_file '.testsrc', <<-EOS.strip_heredoc
233
+ with_env 'HOME' => absolute_path('.') do
234
+ write_file '.testsrc', <<-EOS.strip_heredoc
235
235
  ---
236
236
  opt1: hello world
237
237
  EOS
@@ -254,8 +254,8 @@ RSpec.describe AppConfig do
254
254
  end
255
255
 
256
256
  it 'loads yaml files with the following data types' do
257
- with_environment 'HOME' => working_directory do
258
- create_file '.testsrc', <<-EOS.strip_heredoc
257
+ with_env 'HOME' => absolute_path('.') do
258
+ write_file '.testsrc', <<-EOS.strip_heredoc
259
259
  ---
260
260
  opt1: hello world
261
261
  opt2: :test
@@ -293,8 +293,8 @@ RSpec.describe AppConfig do
293
293
  end
294
294
 
295
295
  it 'raises error on invalid yaml file' do
296
- with_environment 'HOME' => working_directory do
297
- create_file '.testsrc', random_binary_string(100)
296
+ with_env 'HOME' => absolute_path('.') do
297
+ write_file '.testsrc', random_binary_string(100)
298
298
 
299
299
  config_klass = Class.new(AppConfig) do
300
300
  def _class_name
@@ -311,8 +311,8 @@ RSpec.describe AppConfig do
311
311
  end
312
312
 
313
313
  it 'returns an empty config if data file cannot be transformed to hash' do
314
- with_environment 'HOME' => working_directory do
315
- create_file '.testsrc', <<-EOS.strip_heredoc
314
+ with_env 'HOME' => absolute_path('.') do
315
+ write_file '.testsrc', <<-EOS.strip_heredoc
316
316
  ---
317
317
  - hello
318
318
  - world
@@ -339,7 +339,7 @@ RSpec.describe AppConfig do
339
339
 
340
340
  context '#to_s' do
341
341
  it 'outputs a list of variables' do
342
- with_environment 'HOME' => working_directory do
342
+ with_env 'HOME' => absolute_path('.') do
343
343
  config_klass = Class.new(AppConfig) do
344
344
  option :opt1, 'test1'
345
345
  option :opt2, 'test2'
@@ -366,7 +366,7 @@ RSpec.describe AppConfig do
366
366
  end
367
367
 
368
368
  it 'outputs is undefined for blank values (nil, '', ...)' do
369
- with_environment 'HOME' => working_directory do
369
+ with_env 'HOME' => absolute_path('.') do
370
370
  config_klass = Class.new(AppConfig) do
371
371
  option :opt1, nil
372
372
  option :opt2, ''
@@ -397,7 +397,7 @@ RSpec.describe AppConfig do
397
397
 
398
398
  context '#known_options' do
399
399
  it 'outputs a list of known options' do
400
- with_environment 'HOME' => working_directory do
400
+ with_env 'HOME' => absolute_path('.') do
401
401
  config_klass = Class.new(AppConfig) do
402
402
  option :opt1, 'test1'
403
403
  option :opt2, 'test2'
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'fedux_org_stdlib/fixtures_management'
4
+
5
+ RSpec.describe FixturesManagement::FixturesManager do
6
+
7
+ describe '#load_fixtures' do
8
+ let(:creator_stub) { Class.new }
9
+ let(:creator) { stub_const('FeduxOrgStdlib::FixturesManagement::Fixture', creator_stub) }
10
+
11
+ it 'load fixtures from path' do
12
+ expect(creator).to receive(:new).with(Pathname.new(absolute_path('images-app')))
13
+
14
+ touch_file 'images-app/image1.png'
15
+ touch_file 'images-app/image2.png'
16
+
17
+ manager = FixturesManagement::FixturesManager.new
18
+ manager.load_fixtures(absolute_path('.'))
19
+ end
20
+ end
21
+
22
+ describe '#find' do
23
+ it 'find fixture' do
24
+ touch_file 'images-app/image1.png'
25
+ touch_file 'images-app/image2.png'
26
+
27
+ manager = FixturesManagement::FixturesManager.new
28
+ manager.load_fixtures(absolute_path('.'))
29
+
30
+ expect(manager.find('images-app').name).to eq :'images-app'
31
+ end
32
+ end
33
+ end
@@ -5,9 +5,11 @@ require 'fedux_org_stdlib/project/plan'
5
5
  RSpec.describe FeduxOrgStdlib::Project::Plan do
6
6
  context '#to_s' do
7
7
  it 'uses the working directory by default to find plan' do
8
- switch_to_working_directory do
8
+ plan_file = absolute_path('plan.tjp')
9
+
10
+ in_current_dir do
9
11
  plan = FeduxOrgStdlib::Project::Plan.new
10
- expect(plan.to_s).to eq(File.join(Dir.getwd , 'plan.tjp'))
12
+ expect(plan.to_s).to eq plan_file
11
13
  end
12
14
  end
13
15
  end
@@ -4,11 +4,16 @@ require 'fedux_org_stdlib/project/report'
4
4
  require 'fedux_org_stdlib/filesystem'
5
5
 
6
6
  RSpec.describe FeduxOrgStdlib::Project::Report do
7
+ before :each do
8
+ touch_file('plan.tjp')
9
+ touch_file('reports/Overview.html')
10
+ end
11
+
12
+ let(:plan_file) { absolute_path('plan.tjp') }
13
+ let(:report_file) { absolute_path('reports/Overview.html') }
14
+
7
15
  context '#generate' do
8
16
  it 'generates report' do
9
- plan_file = create_file('plan.tjp')
10
- report_file = create_file('reports/Overview.html')
11
-
12
17
  plan = double('Plan')
13
18
  allow(plan).to receive(:to_s).and_return(plan_file)
14
19
  expect(plan).to receive(:needs_to_be_compiled?).with(report_file).and_return(true)
@@ -21,9 +26,6 @@ RSpec.describe FeduxOrgStdlib::Project::Report do
21
26
  end
22
27
 
23
28
  it 'generates report only if plan file is newer than output file' do
24
- plan_file = create_file('plan.tjp')
25
- report_file = create_file('reports/Overview.html')
26
-
27
29
  FileUtils.touch report_file, :mtime => Time.now - 2.hours
28
30
 
29
31
  plan = double('Plan')
@@ -33,16 +35,13 @@ RSpec.describe FeduxOrgStdlib::Project::Report do
33
35
  generator = double('Generator')
34
36
  expect(generator).to receive(:generate_report).once
35
37
 
36
- switch_to_working_directory do
38
+ in_current_dir do
37
39
  report = FeduxOrgStdlib::Project::Report.new(plan: plan, generator: generator, output_file: report_file)
38
40
  report.generate
39
41
  end
40
42
  end
41
43
 
42
44
  it 'does not generate report if plan file is older or of eqal age than output file' do
43
- plan_file = create_file('plan.tjp')
44
- report_file = create_file('reports/Overview.html')
45
-
46
45
  FileUtils.touch plan_file, :mtime => Time.now - 2.hours
47
46
 
48
47
  plan = double('Plan')
@@ -51,7 +50,7 @@ RSpec.describe FeduxOrgStdlib::Project::Report do
51
50
  generator = double('Generator')
52
51
  expect(generator).not_to receive(:generate_report)
53
52
 
54
- switch_to_working_directory do
53
+ in_current_dir do
55
54
  report = FeduxOrgStdlib::Project::Report.new(plan: plan, generator: generator, output_file: report_file)
56
55
 
57
56
  silence(:stderr) do
@@ -65,7 +64,6 @@ RSpec.describe FeduxOrgStdlib::Project::Report do
65
64
  it 'can open a report in a browser' do
66
65
  plan = double('Plan')
67
66
  generator = double('Generator')
68
- report_file = create_file('reports/Overview.html')
69
67
 
70
68
  report = FeduxOrgStdlib::Project::Report.new(plan: plan, generator: generator, output_file: report_file)
71
69
  expect(report).to respond_to :open
@@ -4,34 +4,32 @@ require 'fedux_org_stdlib/project/generators/taskjuggler'
4
4
 
5
5
  RSpec.describe FeduxOrgStdlib::Project::Generators::Taskjuggler do
6
6
  context '#generate_report' do
7
+ before :each do
8
+ create_dir('projects')
9
+ end
10
+
11
+ let(:directory) { absolute_path('projects') }
12
+
7
13
  it "generates a report using taskjuggler" do
8
- directory = create_directory('projects')
9
14
  plan_file = File.join(examples_directory, 'project', 'plan.tjp')
10
15
 
11
16
  generator = FeduxOrgStdlib::Project::Generators::Taskjuggler.new
12
17
 
13
- switch_to_working_directory do
14
- silence(:stderr) do
15
- generator.generate_report(directory, plan_file)
16
- end
18
+ silence(:stderr) do
19
+ generator.generate_report(directory, plan_file)
17
20
  end
18
21
  end
19
22
 
20
23
  it "fails if an error occured while generating the report" do
21
- directory = create_directory('projects')
22
24
  plan_file = File.join(examples_directory, 'project', 'plan_does_not_exist.tjp')
23
25
 
24
26
  generator = FeduxOrgStdlib::Project::Generators::Taskjuggler.new
25
27
 
26
28
  expect {
27
- switch_to_working_directory do
28
- silence(:stderr) do
29
- generator.generate_report(directory, plan_file)
30
- end
31
-
29
+ silence(:stderr) do
30
+ generator.generate_report(directory, plan_file)
32
31
  end
33
32
  }.to raise_error SystemExit
34
-
35
33
  end
36
34
  end
37
35
  end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ require 'aruba/api'
3
+ require 'aruba/reporting'
4
+
5
+ module FeduxOrgStdlib
6
+ # Spec Helpers
7
+ module SpecHelper
8
+ # Helpers for aruba
9
+ module Aruba
10
+ include ::Aruba::Api
11
+
12
+ def dirs
13
+ @dirs ||= %w(tmp rspec)
14
+ end
15
+
16
+ def absolute_path(*args)
17
+ in_current_dir { File.expand_path File.join(*args) }
18
+ end
19
+
20
+ def _create_file(*args)
21
+ super
22
+
23
+ args.first
24
+ end
25
+
26
+ def create_dir(*args)
27
+ super
28
+
29
+ args.first
30
+ end
31
+
32
+ def touch_file(file_name)
33
+ in_current_dir do
34
+ file_name = File.expand_path(file_name)
35
+ _mkdir(File.dirname(file_name))
36
+ FileUtils.touch file_name
37
+ end
38
+
39
+ file_name
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ RSpec.configure do |c|
46
+ c.include FeduxOrgStdlib::SpecHelper::Aruba
47
+ c.before :each do
48
+ clean_current_dir
49
+ restore_env
50
+ end
51
+ end
@@ -6,38 +6,38 @@ RSpec.describe TemplateDirectory do
6
6
 
7
7
  context '#preferred_template_directory' do
8
8
  it 'has a default template file which is the preferred place to store the template' do
9
- with_environment 'HOME' => working_directory do
10
- create_file '.config/my_application/templates/tests.d/test.tt'
9
+ touch_file '.config/my_application/templates/tests.d/test.tt'
11
10
 
12
- template_klass = Class.new(TemplateDirectory) do
13
- def class_name
14
- 'TestTemplateDirectory'
15
- end
11
+ template_klass = Class.new(TemplateDirectory) do
12
+ def class_name
13
+ 'TestTemplateDirectory'
14
+ end
16
15
 
17
- def module_name
18
- 'MyApplication'
19
- end
16
+ def module_name
17
+ 'MyApplication'
20
18
  end
19
+ end
21
20
 
21
+ with_env 'HOME' => absolute_path('.') do
22
22
  template = template_klass.new
23
23
  expect(template.preferred_template_directory).to eq File.expand_path('~/.config/my_application/templates/tests.d')
24
24
  end
25
25
  end
26
26
 
27
27
  it 'works with nested module names' do
28
- with_environment 'HOME' => working_directory do
29
- create_file '.config/my_application/my_sub/templates/tests.d/test.tt'
28
+ touch_file '.config/my_application/my_sub/templates/tests.d/test.tt'
30
29
 
31
- template_klass = Class.new(TemplateDirectory) do
32
- def class_name
33
- 'TestTemplateDirectory'
34
- end
30
+ template_klass = Class.new(TemplateDirectory) do
31
+ def class_name
32
+ 'TestTemplateDirectory'
33
+ end
35
34
 
36
- def module_name
37
- 'MyApplication::MySub'
38
- end
35
+ def module_name
36
+ 'MyApplication::MySub'
39
37
  end
38
+ end
40
39
 
40
+ with_env 'HOME' => absolute_path('.') do
41
41
  template = template_klass.new
42
42
  expect(template.preferred_template_directory).to eq File.expand_path('~/.config/my_application/my_sub/templates/tests.d')
43
43
  end
@@ -46,93 +46,93 @@ RSpec.describe TemplateDirectory do
46
46
 
47
47
  context 'template files' do
48
48
  it 'looks at ~/.config/my_application/templates/tests.d/test.tt' do
49
- with_environment 'HOME' => working_directory do
50
- file = create_file '.config/my_application/templates/tests.d/test.tt', <<-EOS.strip_heredoc
49
+ write_file '.config/my_application/templates/tests.d/test.tt', <<-EOS.strip_heredoc
51
50
  <%= hello world %>
52
- EOS
51
+ EOS
53
52
 
54
- template_klass = Class.new(TemplateDirectory) do
55
- def class_name
56
- 'TestTemplateDirectory'
57
- end
53
+ template_klass = Class.new(TemplateDirectory) do
54
+ def class_name
55
+ 'TestTemplateDirectory'
56
+ end
58
57
 
59
- def module_name
60
- 'MyApplication'
61
- end
58
+ def module_name
59
+ 'MyApplication'
62
60
  end
61
+ end
63
62
 
63
+ with_env 'HOME' => absolute_path('.') do
64
64
  template = template_klass.new
65
- expect(template.template_files).to include file
65
+ expect(template.template_files).to include absolute_path('.config/my_application/templates/tests.d/test.tt')
66
66
  end
67
67
  end
68
68
 
69
69
  it 'looks at ~/.my_application/templates/tests.d/test.tt' do
70
- with_environment 'HOME' => working_directory do
71
- file = create_file '.my_application/templates/tests.d/test.tt', <<-EOS.strip_heredoc
70
+ write_file '.my_application/templates/tests.d/test.tt', <<-EOS.strip_heredoc
72
71
  <%= hello world %>
73
- EOS
72
+ EOS
74
73
 
75
- template_klass = Class.new(TemplateDirectory) do
76
- def class_name
77
- 'TestTemplateDirectory'
78
- end
74
+ template_klass = Class.new(TemplateDirectory) do
75
+ def class_name
76
+ 'TestTemplateDirectory'
77
+ end
79
78
 
80
- def module_name
81
- 'MyApplication'
82
- end
79
+ def module_name
80
+ 'MyApplication'
83
81
  end
82
+ end
84
83
 
84
+ with_env 'HOME' => absolute_path('.') do
85
85
  template = template_klass.new
86
- expect(template.template_files).to include file
86
+ expect(template.template_files).to include absolute_path('.my_application/templates/tests.d/test.tt')
87
87
  end
88
88
  end
89
89
 
90
90
  it 'returns templates in subdirectories as well' do
91
- with_environment 'HOME' => working_directory do
92
- file = create_file '.my_application/templates/tests.d/blub/test.tt', <<-EOS.strip_heredoc
91
+ write_file '.my_application/templates/tests.d/blub/test.tt', <<-EOS.strip_heredoc
93
92
  <%= hello world %>
94
- EOS
93
+ EOS
95
94
 
96
- template_klass = Class.new(TemplateDirectory) do
97
- def class_name
98
- 'TestTemplateDirectory'
99
- end
95
+ template_klass = Class.new(TemplateDirectory) do
96
+ def class_name
97
+ 'TestTemplateDirectory'
98
+ end
100
99
 
101
- def module_name
102
- 'MyApplication'
103
- end
100
+ def module_name
101
+ 'MyApplication'
104
102
  end
103
+ end
105
104
 
105
+ with_env 'HOME' => absolute_path('.') do
106
106
  template = template_klass.new
107
- expect(template.template_files).to include file
107
+ expect(template.template_files).to include absolute_path('.my_application/templates/tests.d/blub/test.tt')
108
108
  end
109
109
  end
110
110
  end
111
111
 
112
112
  context '#template_files' do
113
113
  it 'returns template_files in template directory' do
114
- with_environment 'HOME' => working_directory do
115
- file1 = create_file '.my_application/templates/tests.d/test1.tt', <<-EOS.strip_heredoc
114
+ write_file '.my_application/templates/tests.d/test1.tt', <<-EOS.strip_heredoc
116
115
  <%= hello world %>
117
- EOS
116
+ EOS
118
117
 
119
- file2 = create_file '.my_application/templates/tests.d/test2.tt', <<-EOS.strip_heredoc
118
+ write_file '.my_application/templates/tests.d/test2.tt', <<-EOS.strip_heredoc
120
119
  <%= hello world %>
121
- EOS
120
+ EOS
122
121
 
123
- template_klass = Class.new(TemplateDirectory) do
124
- def class_name
125
- 'TestTemplateDirectory'
126
- end
122
+ template_klass = Class.new(TemplateDirectory) do
123
+ def class_name
124
+ 'TestTemplateDirectory'
125
+ end
127
126
 
128
- def module_name
129
- 'MyApplication'
130
- end
127
+ def module_name
128
+ 'MyApplication'
131
129
  end
130
+ end
132
131
 
132
+ with_env 'HOME' => absolute_path('.') do
133
133
  template = template_klass.new
134
- expect(template.template_files).to include file1
135
- expect(template.template_files).to include file2
134
+ expect(template.template_files).to include absolute_path('.my_application/templates/tests.d/test1.tt')
135
+ expect(template.template_files).to include absolute_path('.my_application/templates/tests.d/test2.tt')
136
136
  end
137
137
  end
138
138
  end
@@ -6,8 +6,8 @@ RSpec.describe FileTemplate do
6
6
 
7
7
  context '#proposed_file' do
8
8
  it 'generates a propose file path based on template basename' do
9
- with_environment 'HOME' => working_directory do
10
- create_file '.config/my_application/templates/test.tt'
9
+ with_env 'HOME' => absolute_path('.') do
10
+ touch_file '.config/my_application/templates/test.tt'
11
11
 
12
12
  template_klass = Class.new(FileTemplate) do
13
13
  def class_name
@@ -19,16 +19,16 @@ RSpec.describe FileTemplate do
19
19
  end
20
20
  end
21
21
 
22
- template = template_klass.new(working_directory: working_directory)
23
- expect(template.proposed_file).to eq File.join(working_directory, 'test')
22
+ template = template_klass.new(working_directory: absolute_path('.'))
23
+ expect(template.proposed_file).to eq absolute_path('test')
24
24
  end
25
25
  end
26
26
  end
27
27
 
28
28
  context '#preferred_template_file' do
29
29
  it 'has a default template file which is the preferred place to store the template' do
30
- with_environment 'HOME' => working_directory do
31
- create_file '.config/my_application/templates/test.tt'
30
+ with_env 'HOME' => absolute_path('.') do
31
+ touch_file '.config/my_application/templates/test.tt'
32
32
 
33
33
  template_klass = Class.new(FileTemplate) do
34
34
  def class_name
@@ -46,8 +46,8 @@ RSpec.describe FileTemplate do
46
46
  end
47
47
 
48
48
  it 'works with nested module names' do
49
- with_environment 'HOME' => working_directory do
50
- create_file '.config/my_application/my_sub/templates/test.tt'
49
+ with_env 'HOME' => absolute_path('.') do
50
+ touch_file '.config/my_application/my_sub/templates/test.tt'
51
51
 
52
52
  template_klass = Class.new(FileTemplate) do
53
53
  def class_name
@@ -67,8 +67,8 @@ RSpec.describe FileTemplate do
67
67
 
68
68
  context 'template files' do
69
69
  it 'looks at ~/.config/my_application/templates/test.tt' do
70
- with_environment 'HOME' => working_directory do
71
- create_file '.config/my_application/templates/test.tt', <<-EOS.strip_heredoc
70
+ with_env 'HOME' => absolute_path('.') do
71
+ write_file '.config/my_application/templates/test.tt', <<-EOS.strip_heredoc
72
72
  <%= hello world %>
73
73
  EOS
74
74
 
@@ -88,8 +88,8 @@ RSpec.describe FileTemplate do
88
88
  end
89
89
 
90
90
  it 'looks at ~/.my_application/templates/test.tt' do
91
- with_environment 'HOME' => working_directory do
92
- create_file '.my_application/templates/test.tt', <<-EOS.strip_heredoc
91
+ with_env 'HOME' => absolute_path('.') do
92
+ write_file '.my_application/templates/test.tt', <<-EOS.strip_heredoc
93
93
  <%= hello world %>
94
94
  EOS
95
95
 
@@ -109,8 +109,8 @@ RSpec.describe FileTemplate do
109
109
  end
110
110
 
111
111
  it 'supports star operator in suffix: ~/.my_application/templates/test*.tt' do
112
- with_environment 'HOME' => working_directory do
113
- create_file '.my_application/templates/test.erb.tt', <<-EOS.strip_heredoc
112
+ with_env 'HOME' => absolute_path('.') do
113
+ write_file '.my_application/templates/test.erb.tt', <<-EOS.strip_heredoc
114
114
  <%= hello world %>
115
115
  EOS
116
116
 
@@ -132,8 +132,8 @@ RSpec.describe FileTemplate do
132
132
 
133
133
  context '#content' do
134
134
  it 'returns content of template file' do
135
- with_environment 'HOME' => working_directory do
136
- create_file '.my_application/templates/test.tt', <<-EOS.strip_heredoc
135
+ with_env 'HOME' => absolute_path('.') do
136
+ write_file '.my_application/templates/test.tt', <<-EOS.strip_heredoc
137
137
  <%= hello world %>
138
138
  EOS
139
139
 
@@ -155,8 +155,8 @@ RSpec.describe FileTemplate do
155
155
 
156
156
  context '#proposed_extname' do
157
157
  it 'propose a erb as default extname' do
158
- with_environment 'HOME' => working_directory do
159
- create_file '.my_application/templates/test.tt'
158
+ with_env 'HOME' => absolute_path('.') do
159
+ touch_file '.my_application/templates/test.tt'
160
160
 
161
161
  template_klass = Class.new(FileTemplate) do
162
162
  def class_name
@@ -174,8 +174,8 @@ RSpec.describe FileTemplate do
174
174
  end
175
175
 
176
176
  it 'extracts the extname from file name' do
177
- with_environment 'HOME' => working_directory do
178
- create_file '.my_application/templates/test.md.tt'
177
+ with_env 'HOME' => absolute_path('.') do
178
+ touch_file '.my_application/templates/test.md.tt'
179
179
 
180
180
  template_klass = Class.new(FileTemplate) do
181
181
  def class_name
@@ -7,57 +7,65 @@ RSpec.describe FeduxOrgStdlib::VersionManagement::RubygemVersionFileParser do
7
7
 
8
8
  context '#parse' do
9
9
  it 'extracts version number' do
10
- version_file = create_file('version.rb', <<-EOS.strip_heredoc
11
- #main MyLibrary
12
- module MyLibrary
13
- VERSION = '0.0.0'
14
- end
15
- EOS
16
- )
10
+ write_file(
11
+ 'version.rb',
12
+ <<-EOS.strip_heredoc
13
+ #main MyLibrary
14
+ module MyLibrary
15
+ VERSION = '0.0.0'
16
+ end
17
+ EOS
18
+ )
17
19
 
18
- parser.parse(version_file)
20
+ parser.parse(absolute_path('version.rb'))
19
21
 
20
22
  expect(parser.version).to eq('0.0.0')
21
23
  end
22
24
 
23
25
  it 'extracts modules' do
24
- version_file = create_file('version.rb', <<-EOS.strip_heredoc
25
- #main MyLibrary
26
- module MyLibrary
27
- VERSION = '0.0.0'
28
- end
29
- EOS
30
- )
26
+ write_file(
27
+ 'version.rb',
28
+ <<-EOS.strip_heredoc
29
+ #main MyLibrary
30
+ module MyLibrary
31
+ VERSION = '0.0.0'
32
+ end
33
+ EOS
34
+ )
31
35
 
32
- parser.parse(version_file)
36
+ parser.parse(absolute_path('version.rb'))
33
37
 
34
38
  expect(parser.modules).to eq([ 'MyLibrary' ])
35
39
  end
36
40
 
37
41
  it 'extracts nested modules as well' do
38
- version_file = create_file('version.rb', <<-EOS.strip_heredoc
39
- #main MyLibrary
40
- module MyLibrary
41
- module MyClass
42
- VERSION = '0.0.0'
43
- end
44
- end
45
- EOS
46
- )
42
+ write_file(
43
+ 'version.rb',
44
+ <<-EOS.strip_heredoc
45
+ #main MyLibrary
46
+ module MyLibrary
47
+ module MyClass
48
+ VERSION = '0.0.0'
49
+ end
50
+ end
51
+ EOS
52
+ )
47
53
 
48
- parser.parse(version_file)
54
+ parser.parse(absolute_path('version.rb'))
49
55
 
50
- expect(parser.modules).to eq([ 'MyLibrary', 'MyClass' ])
56
+ expect(parser.modules).to eq(['MyLibrary', 'MyClass'])
51
57
  end
52
58
 
53
59
  it 'fails if version cannot be extracted' do
54
- version_file = create_file('version.rb', <<-EOS.strip_heredoc
55
- #main MyLibrary
56
- EOS
57
- )
60
+ write_file(
61
+ 'version.rb',
62
+ <<-EOS.strip_heredoc
63
+ #main MyLibrary
64
+ EOS
65
+ )
58
66
 
59
67
  expect {
60
- parser.parse(version_file)
68
+ parser.parse(absolute_path('version.rb'))
61
69
  }.to raise_error VersionManagement::Exceptions::VersionFileInvalid
62
70
  end
63
71
  end
@@ -53,7 +53,7 @@ RSpec.describe FeduxOrgStdlib::VersionManagement::RubygemVersionFile do
53
53
  expect(library).to receive(:module_names).and_return([ 'MyLibrary', 'MyClass' ])
54
54
  version_file = FeduxOrgStdlib::VersionManagement::RubygemVersionFile.new(version, library)
55
55
 
56
- switch_to_working_directory do
56
+ in_current_dir do
57
57
  version_file.write('version.rb')
58
58
  expect(File).to be_exists('version.rb')
59
59
  end
@@ -75,7 +75,7 @@ RSpec.describe FeduxOrgStdlib::VersionManagement::RubygemVersionFile do
75
75
  expect(parser).to receive(:version).and_return('0.0.0')
76
76
  expect(parser).to receive(:modules).and_return([ 'MyModule' ])
77
77
 
78
- version_file = create_file('version.rb', <<-EOS.strip_heredoc
78
+ version_file = write_file('version.rb', <<-EOS.strip_heredoc
79
79
  # encoding: utf-8
80
80
  # MyLibrary
81
81
  module MyLibrary
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedux_org-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.19
4
+ version: 0.7.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Meyer
@@ -74,6 +74,10 @@ files:
74
74
  - lib/fedux_org_stdlib/file_template/exceptions.rb
75
75
  - lib/fedux_org_stdlib/filesystem.rb
76
76
  - lib/fedux_org_stdlib/filesystem/exceptions.rb
77
+ - lib/fedux_org_stdlib/fixtures_management.rb
78
+ - lib/fedux_org_stdlib/fixtures_management/fixture.rb
79
+ - lib/fedux_org_stdlib/fixtures_management/fixtures_manager.rb
80
+ - lib/fedux_org_stdlib/fixtures_management/no_fixture.rb
77
81
  - lib/fedux_org_stdlib/gem_plugins.rb
78
82
  - lib/fedux_org_stdlib/gem_plugins/exceptions.rb
79
83
  - lib/fedux_org_stdlib/gem_plugins/no_plugin.rb
@@ -136,6 +140,8 @@ files:
136
140
  - lib/fedux_org_stdlib/rake_tasks/tests/rspec.rb
137
141
  - lib/fedux_org_stdlib/rake_tasks/tests/travis.rb
138
142
  - lib/fedux_org_stdlib/require_files.rb
143
+ - lib/fedux_org_stdlib/roles/comparable_by_name.rb
144
+ - lib/fedux_org_stdlib/roles/versionable.rb
139
145
  - lib/fedux_org_stdlib/shell_language_detector.rb
140
146
  - lib/fedux_org_stdlib/shell_language_detector/language.rb
141
147
  - lib/fedux_org_stdlib/support_information.rb
@@ -149,7 +155,6 @@ files:
149
155
  - lib/fedux_org_stdlib/version_management/rubygem_version_file_parser.rb
150
156
  - lib/fedux_org_stdlib/version_management/software_version.rb
151
157
  - lib/fedux_org_stdlib/version_management/version_builder.rb
152
- - lib/fedux_org_stdlib/versionable.rb
153
158
  - rakefiles/default.rake
154
159
  - rakefiles/travis.rake
155
160
  - script/console
@@ -176,6 +181,7 @@ files:
176
181
  - spec/examples/models/filesystem_based/find_files/abc.rb.swp
177
182
  - spec/examples/models/filesystem_based/find_files/cde.rb
178
183
  - spec/examples/project/plan.tjp
184
+ - spec/fixtures_management/fixtures_manager_spec.rb
179
185
  - spec/gem_plugins/plugin_manager_spec.rb
180
186
  - spec/list_spec.rb
181
187
  - spec/logger/logger_spec.rb
@@ -192,8 +198,7 @@ files:
192
198
  - spec/project/taskjuggler_spec.rb
193
199
  - spec/shell_language_detector_spec.rb
194
200
  - spec/spec_helper.rb
195
- - spec/support/environment.rb
196
- - spec/support/filesystem.rb
201
+ - spec/support/aruba.rb
197
202
  - spec/support/generator.rb
198
203
  - spec/support/reporting.rb
199
204
  - spec/support/rspec.rb
@@ -254,6 +259,7 @@ test_files:
254
259
  - spec/examples/models/filesystem_based/find_files/abc.rb.swp
255
260
  - spec/examples/models/filesystem_based/find_files/cde.rb
256
261
  - spec/examples/project/plan.tjp
262
+ - spec/fixtures_management/fixtures_manager_spec.rb
257
263
  - spec/gem_plugins/plugin_manager_spec.rb
258
264
  - spec/list_spec.rb
259
265
  - spec/logger/logger_spec.rb
@@ -270,8 +276,7 @@ test_files:
270
276
  - spec/project/taskjuggler_spec.rb
271
277
  - spec/shell_language_detector_spec.rb
272
278
  - spec/spec_helper.rb
273
- - spec/support/environment.rb
274
- - spec/support/filesystem.rb
279
+ - spec/support/aruba.rb
275
280
  - spec/support/generator.rb
276
281
  - spec/support/reporting.rb
277
282
  - spec/support/rspec.rb
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
- require 'fedux_org_stdlib/rake/exceptions'
3
-
4
- module FeduxOrgStdlib
5
- module Versionable
6
- def version_file(working_directory = Dir.getwd)
7
- paths = []
8
- paths << File.join(working_directory, 'lib', '**', 'version.rb')
9
-
10
- file = Dir.glob(paths.shift).first while !paths.blank? and file.blank?
11
-
12
- raise FeduxOrgStdlib::Rake::Exceptions::VersionFileNotFound, JSON.dump(message: 'Cannot find version file') unless file
13
-
14
- file
15
- end
16
- end
17
- end
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
- require 'fedux_org_stdlib/environment'
3
-
4
- module FeduxOrgStdlib
5
- module SpecHelper
6
- module Environment
7
- include FeduxOrgStdlib::Environment
8
- alias_method :with_environment, :isolated_environment
9
- end
10
- end
11
- end
12
-
13
- RSpec.configure do |c|
14
- c.include FeduxOrgStdlib::SpecHelper::Environment
15
- end
16
-
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
- require 'fedux_org_stdlib/filesystem'
3
-
4
- module FeduxOrgStdlib
5
- module SpecHelper
6
- module Filesystem
7
- include FeduxOrgStdlib::Filesystem
8
-
9
- def root_directory
10
- ::File.expand_path('../../../', __FILE__)
11
- end
12
- end
13
- end
14
- end
15
-
16
- RSpec.configure do |c|
17
- c.include FeduxOrgStdlib::SpecHelper::Filesystem
18
- c.before(:each) { cleanup_working_directory }
19
- end