features/generator_spec.feature in ammeter-1.1.0 vs features/generator_spec.feature in ammeter-1.1.1

- old
+ new

@@ -8,52 +8,65 @@ Given a file named "lib/generators/awesome/awesome_generator.rb" with: """ class AwesomeGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) class_option :super, :type => :boolean, :default => false + class_option :someone, :type => :string def create_awesomeness template 'awesome.html', File.join('public', name, "#{"super_" if options[:super]}awesome.html") end def create_lameness - template 'lame.html', File.join('public', name, "#{"super_" if options[:super]}lame.html") + template 'lame.html.erb', File.join('public', name, "#{"super_" if options[:super]}lame.html") end end """ And a file named "lib/generators/awesome/templates/awesome.html" with: """ This is an awesome file """ - And a file named "lib/generators/awesome/templates/lame.html" with: + And a file named "lib/generators/awesome/templates/lame.html.erb" with: """ - This is a lame file + <%= options[:someone] %> is lame """ Scenario: A spec that runs the entire generator Given a file named "spec/generators/awesome_generator_spec.rb" with: """ require "rails_helper" require 'generators/awesome/awesome_generator' describe AwesomeGenerator do - before { run_generator %w(my_dir) } - describe 'public/my_dir/awesome.html' do + describe 'invoke' do + before { run_generator %w(my_dir --someone Alex) } + describe 'public/my_dir/awesome.html' do + subject { file('public/my_dir/awesome.html') } + it { expect(subject).to exist } + it { expect(subject).to contain 'This is an awesome file' } + it { expect(subject).to_not contain 'This text is not in the file' } + end + describe 'public/my_dir/lame.html' do + subject { file('public/my_dir/lame.html') } + it { expect(subject).to exist } + it { expect(subject).to contain 'Alex is lame' } + it { expect(subject).to_not contain 'This text is not in the file' } + end + end + describe 'revoke' do subject { file('public/my_dir/awesome.html') } - it { expect(subject).to exist } - it { expect(subject).to contain 'This is an awesome file' } - it { expect(subject).to_not contain 'This text is not in the file' } + it 'can run a reverse migration' do + FileUtils.mkdir_p(File.dirname(subject)) + File.write(subject, "test file") + expect(subject).to exist + run_generator %w(my_dir --someone Alex), behavior: :revoke + expect(subject).not_to exist + end end - describe 'public/my_dir/lame.html' do - subject { file('public/my_dir/lame.html') } - it { expect(subject).to exist } - it { expect(subject).to contain 'This is a lame file' } - it { expect(subject).to_not contain 'This text is not in the file' } - end end """ When I run `rake spec` - Then the output should contain "6 examples, 0 failures" + Then the output should contain "7 examples, 0 failures" Scenario: A spec that runs one task in the generator Given a file named "spec/generators/another_awesome_generator_spec.rb" with: """ require "rails_helper"