From c6d585bc5777d3e35617c64b014a8736220730df Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 1 Feb 2018 13:37:52 +0100 Subject: [PATCH 1/4] adds spec/features loader [fixes SCI-1998] --- .gitignore | 4 +++ config/initializers/load_addons_specs.rb | 45 ++++++++++++++++++++++++ features/addons/.gitkeep | 0 features/addons/organization_management | 1 + spec/addons/organization_management | 1 + 5 files changed, 51 insertions(+) create mode 100644 config/initializers/load_addons_specs.rb create mode 100644 features/addons/.gitkeep create mode 120000 features/addons/organization_management create mode 120000 spec/addons/organization_management diff --git a/.gitignore b/.gitignore index 74a9d77c9..882fd2676 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,7 @@ coverage /node_modules .DS_Store app/javascript/src/componentLoader/components/* + +# ignore addon features +features/addons/* +!features/addons/.gitkeep diff --git a/config/initializers/load_addons_specs.rb b/config/initializers/load_addons_specs.rb new file mode 100644 index 000000000..feafb1f8e --- /dev/null +++ b/config/initializers/load_addons_specs.rb @@ -0,0 +1,45 @@ +require 'singleton' + +class AddonsSpecLoader + include Singleton + include AddonsHelper + + # rspec will recognise symlinks in the second run + def mount + FileUtils.rm_f Dir.glob("#{Dir.pwd}/spec/addons/*") + available_addons.each do |addon| + specs_path = "addons/#{addon}/spec" + next unless Dir.exist? specs_path + File.symlink("#{Dir.pwd}/#{specs_path}", + "#{Dir.pwd}/spec/addons/#{addon}") + end + end + + # cucumber can't respolve path with symlinks so we copy files from addons + def copy_to_features + FileUtils.rm_f Dir.glob("#{Dir.pwd}/features/addons/*") + available_addons.each do |addon| + feature_path = "addons/#{addon}/features" + FileUtils.copy_entry("#{Dir.pwd}/#{feature_path}", + "#{Dir.pwd}/features/addons/#{addon}") + end + end + + private + + def available_addons + list_all_addons.map { |addon| addon.to_s.split('::').last.underscore } + end +end + +if ENV['RAILS_ENV'].in? %w(test development) + begin + puts '[sciNote] Generating symlinks for addons!' + puts '[sciNote] Copying features from addons!' + AddonsSpecLoader.instance.mount + AddonsSpecLoader.instance.copy_to_features + rescue + puts '[sciNote] Unable to load specs from addons!' + puts '[sciNote] Your system does not support symlink!' + end +end diff --git a/features/addons/.gitkeep b/features/addons/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/features/addons/organization_management b/features/addons/organization_management new file mode 120000 index 000000000..eb9762c71 --- /dev/null +++ b/features/addons/organization_management @@ -0,0 +1 @@ +/usr/src/app/addons/organization_management/features \ No newline at end of file diff --git a/spec/addons/organization_management b/spec/addons/organization_management new file mode 120000 index 000000000..052f6f0ce --- /dev/null +++ b/spec/addons/organization_management @@ -0,0 +1 @@ +/usr/src/app/addons/organization_management/spec \ No newline at end of file From 952173fbd60c15d3866bbc210398892e18b8e558 Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 1 Feb 2018 14:03:36 +0100 Subject: [PATCH 2/4] escape if no feature folder present --- config/initializers/load_addons_specs.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/initializers/load_addons_specs.rb b/config/initializers/load_addons_specs.rb index feafb1f8e..5ca676900 100644 --- a/config/initializers/load_addons_specs.rb +++ b/config/initializers/load_addons_specs.rb @@ -20,6 +20,7 @@ class AddonsSpecLoader FileUtils.rm_f Dir.glob("#{Dir.pwd}/features/addons/*") available_addons.each do |addon| feature_path = "addons/#{addon}/features" + next unless Dir.exist? feature_path FileUtils.copy_entry("#{Dir.pwd}/#{feature_path}", "#{Dir.pwd}/features/addons/#{addon}") end From 60d1fb5e66ae0d11e4f670aee5c2efd53698c5f2 Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 1 Feb 2018 15:31:36 +0100 Subject: [PATCH 3/4] fixes gitignore --- .gitignore | 4 +++- features/addons/organization_management | 1 - spec/addons/organization_management | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) delete mode 120000 features/addons/organization_management delete mode 120000 spec/addons/organization_management diff --git a/.gitignore b/.gitignore index 882fd2676..ca8925268 100644 --- a/.gitignore +++ b/.gitignore @@ -64,5 +64,7 @@ coverage app/javascript/src/componentLoader/components/* # ignore addon features -features/addons/* +features/addons +spec/addons !features/addons/.gitkeep +!spec/addons/.gitkeep diff --git a/features/addons/organization_management b/features/addons/organization_management deleted file mode 120000 index eb9762c71..000000000 --- a/features/addons/organization_management +++ /dev/null @@ -1 +0,0 @@ -/usr/src/app/addons/organization_management/features \ No newline at end of file diff --git a/spec/addons/organization_management b/spec/addons/organization_management deleted file mode 120000 index 052f6f0ce..000000000 --- a/spec/addons/organization_management +++ /dev/null @@ -1 +0,0 @@ -/usr/src/app/addons/organization_management/spec \ No newline at end of file From 2684d2b515eeb41d291c7ff58fdcb305570a3b82 Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 1 Feb 2018 15:34:40 +0100 Subject: [PATCH 4/4] fix typo --- config/initializers/load_addons_specs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/load_addons_specs.rb b/config/initializers/load_addons_specs.rb index 5ca676900..27b6df7da 100644 --- a/config/initializers/load_addons_specs.rb +++ b/config/initializers/load_addons_specs.rb @@ -15,7 +15,7 @@ class AddonsSpecLoader end end - # cucumber can't respolve path with symlinks so we copy files from addons + # cucumber cannot resolve path with symlinks so we copy files from addons def copy_to_features FileUtils.rm_f Dir.glob("#{Dir.pwd}/features/addons/*") available_addons.each do |addon|