Last active
March 27, 2019 11:01
-
-
Save nevadajames/fc75b5d5d3056a6652699c11f23fadab to your computer and use it in GitHub Desktop.
Test generator for after_party tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AfterPartyTestGenerator < Rails::Generators::NamedBase | |
| source_root File.expand_path('../templates', __FILE__) | |
| def create_test_file | |
| @clean_file_name = file_name.gsub(/\d{14}_{1}/, '') | |
| return file_exist_warning if File.exist?(file_extension) | |
| template "test_template.erb", file_extension | |
| end | |
| private | |
| def file_extension | |
| "spec/lib/tasks/deployment/#{@clean_file_name}_spec.rb" | |
| end | |
| def file_exist_warning | |
| puts "A file with name #{file_extension} already exists" | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rails_helper' | |
| describe '<%= @clean_file_name %>', type: :task do | |
| before :each do | |
| Rake.application.rake_require 'tasks/deployment/<%= file_name %>' | |
| Rake::Task.define_task(:environment) | |
| end | |
| subject { Rake::Task['after_party:<%= @clean_file_name %>'].execute } | |
| it 'works' do | |
| expect{ subject }.not_to raise_error | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Description: | |
| Generates a basic rspec test template for rake after_party task | |
| Example: | |
| rails generate after_party_test 2019112233_your_task_name | |
| This will create: | |
| spec/lib/task/deploy/your_task_name_spec.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment