Commit adb536b0 authored by Laurent Briais's avatar Laurent Briais

Improved generated plugin tests skeleton.

parent 7d999d7f
module PowerStencilTests
module Project
TEMP_DIR_PREFIX = 'PS_TESTS_'
module ClassMethods
def temporary_project(project_name, with_git_support: false, scope: :all)
self.instance_eval do
puts scope
around(scope) do |execution|
Dir.mktmpdir(TEMP_DIR_PREFIX) do |tests_root_dir|
tmp_project_path = File.join tests_root_dir, project_name
create_project_including_this_plugin tmp_project_path, with_git_support: with_git_support
execution.run
@tmp_project_path = nil
end
end
end
end
def plugin_path
File.expand_path File.join('..', '..'), __FILE__
end
end
attr_reader :tmp_project_path
def self.included(base)
base.extend(ClassMethods)
end
def create_project_including_this_plugin(project_path, with_git_support: false)
cmd = "power_stencil init --project-path '#{project_path}'"
cmd << ' --no-git' unless with_git_support
`#{cmd}`
project_plugin_path = File.join project_path, '.ps_project', 'plugins'
`ln -s '#{self.class.plugin_path}' '#{project_plugin_path}'`
@tmp_project_path = project_path
end
def temporary_project_cmd(params)
"power_stencil #{params} --project-path '#{tmp_project_path}'"
end
end
end
\ No newline at end of file
require "bundler/setup"
require 'bundler/setup'
require 'power_stencil'
require "<%= plugin_name %>"
require 'project_helper'
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
......
RSpec.describe <%= plugin_module_name %> do
include PowerStencilTests::Project
temporary_project 'test_project', scope: :all
let(:plugin_list) { 'plugin --list' }
let(:test_entity) { '<%= plugin_name %>/test_<%= plugin_name %>' }
let(:create_release) { "create #{test_entity}" }
let(:get_release) { "get #{test_entity}" }
it 'has a version number' do
expect(<%= plugin_module_name %>::VERSION).not_to be nil
end
it 'does something useful' do
pending 'Tests implementation'
RSpec.fail
it 'should add a <%= plugin_name %> sub-command' do
expect(`#{temporary_project_cmd info_cmd}`).to match '- <%= plugin_name %>'
end
it 'should be possible to create a release' do
`#{temporary_project_cmd create_release}`
expect($?.success?).to be_truthy
expect(`#{temporary_project_cmd get_release}`).not_to be_empty
end
end
module PowerStencilTests
module Project
TEMP_DIR_PREFIX = 'PS_TESTS_'
module ClassMethods
def temporary_project(project_name, with_git_support: false, scope: :all)
self.instance_eval do
puts scope
around(scope) do |execution|
Dir.mktmpdir(TEMP_DIR_PREFIX) do |tests_root_dir|
tmp_project_path = File.join tests_root_dir, project_name
create_project_including_this_plugin tmp_project_path, with_git_support: with_git_support
execution.run
@tmp_project_path = nil
end
end
end
end
def plugin_path
File.expand_path File.join('..', '..'), __FILE__
end
end
attr_reader :tmp_project_path
def self.included(base)
base.extend(ClassMethods)
end
def create_project_including_this_plugin(project_path, with_git_support: false)
cmd = "power_stencil init --project-path '#{project_path}'"
cmd << ' --no-git' unless with_git_support
`#{cmd}`
project_plugin_path = File.join project_path, '.ps_project', 'plugins'
`ln -s '#{self.class.plugin_path}' '#{project_plugin_path}'`
@tmp_project_path = project_path
end
def temporary_project_cmd(params)
"power_stencil #{params} --project-path '#{tmp_project_path}'"
end
end
end
require "bundler/setup"
require 'bundler/setup'
require 'power_stencil'
require "<%= plugin_name %>"
require 'project_helper'
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
......
RSpec.describe <%= plugin_module_name %> do
include PowerStencilTests::Project
temporary_project 'test_project', scope: :all
let(:plugin_list) { 'plugin --list' }
let(:test_entity) { '<%= plugin_name %>/test_<%= plugin_name %>' }
let(:create_release) { "create #{test_entity}" }
let(:get_release) { "get #{test_entity}" }
it 'has a version number' do
expect(<%= plugin_module_name %>::VERSION).not_to be nil
end
it 'does something useful' do
pending 'Tests implementation'
RSpec.fail
it 'should add a <%= plugin_name %> sub-command' do
expect(`#{temporary_project_cmd info_cmd}`).to match '- <%= plugin_name %>'
end
it 'should be possible to create a release' do
`#{temporary_project_cmd create_release}`
expect($?.success?).to be_truthy
expect(`#{temporary_project_cmd get_release}`).not_to be_empty
end
end
......@@ -41,8 +41,8 @@ module PowerStencil
end
puts_and_logs "Generated templates in '#{new_entity.templates_path}'.", check_verbose: false if new_entity.buildable?
rescue => e
puts_and_logs "Failed to create '#{search_criterion.as_path}' with message '#{e.message}'.", logs_as: :error, check_verbose: false
logger.debug PowerStencil::Error.report_error(e)
raise PowerStencil::Error, "Failed to create '#{search_criterion.as_path}' with message '#{e.message}'."
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment