Skip to content

Commit

Permalink
specs and scenarios for negative cases (failure messages)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrothenberg committed Oct 13, 2011
1 parent de0ce70 commit 2d681cc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
23 changes: 22 additions & 1 deletion features/generator_spec.feature
Expand Up @@ -94,11 +94,20 @@ Feature: generator spec
subject { file('public/my_dir/awesome.html') }
it { should_not contain 'This is an awesome file' }
it { should contain 'This text is not in the file' }
it { should_not exist }
end
describe 'public/my_dir/non_existent.html' do
subject { file('public/my_dir/non_existent.html') }
it { should exist }
end
describe 'db/migrate/non_existent_migration.rb' do
subject { migration_file('db/migrate/non_existent_migration.rb') }
it { should exist }
end
end
"""
When I run `rake spec`
Then the output should contain "2 examples, 2 failures"
Then the output should contain "5 examples, 5 failures"
And the output should contain:
"""
/tmp/public/my_dir/awesome.html to not contain "This is an awesome file" but it did
Expand All @@ -107,6 +116,18 @@ Feature: generator spec
"""
/tmp/public/my_dir/awesome.html to contain "This text is not in the file" but it contained "This is an awesome file"
"""
And the output should contain:
"""
/tmp/public/my_dir/awesome.html" not to exist
"""
And the output should contain:
"""
/tmp/public/my_dir/non_existent.html" to exist
"""
And the output should contain:
"""
db/migrate/TIMESTAMP_non_existent_migration.rb" to exist
"""

Scenario: A generator that creates a migration
Given a file named "spec/generators/a_migration_spec.rb" with:
Expand Down
Expand Up @@ -69,7 +69,9 @@ def file relative
end
def migration_file relative
file_path = file(relative)
Dir.glob("#{File.dirname(file_path)}/[0-9]*_#{File.basename(file_path)}").first
migration_file = Dir.glob("#{File.dirname(file_path)}/[0-9]*_#{File.basename(file_path)}").first
migration_file = "#{File.dirname(file_path)}/TIMESTAMP_#{File.basename(file_path)}" if migration_file.nil?
migration_file
end
end
end
Expand Down
Expand Up @@ -53,13 +53,19 @@ module Ammeter::RSpec::Rails
group.file('app/model/post.rb').should == "#{path_to_gem_root_tmp}/app/model/post.rb"
end

it 'should use destination to find relative root file' do
tmp_db_migrate = path_to_gem_root_tmp + '/db/migrate'
FileUtils.mkdir_p tmp_db_migrate
FileUtils.touch(tmp_db_migrate + '/20111010200000_create_comments.rb')
FileUtils.touch(tmp_db_migrate + '/20111010203337_create_posts.rb')

group.migration_file('db/migrate/create_posts.rb').should == "#{path_to_gem_root_tmp}/db/migrate/20111010203337_create_posts.rb"
describe 'migrations' do
before do
tmp_db_migrate = path_to_gem_root_tmp + '/db/migrate'
FileUtils.mkdir_p tmp_db_migrate
FileUtils.touch(tmp_db_migrate + '/20111010200000_create_comments.rb')
FileUtils.touch(tmp_db_migrate + '/20111010203337_create_posts.rb')
end
it 'should use destination to find relative root file' do
group.migration_file('db/migrate/create_posts.rb').should == "#{path_to_gem_root_tmp}/db/migrate/20111010203337_create_posts.rb"
end
it 'should stick "TIMESTAMP" in when migration does not exist' do
group.migration_file('db/migrate/migration_that_is_not_there.rb').should == "#{path_to_gem_root_tmp}/db/migrate/TIMESTAMP_migration_that_is_not_there.rb"
end
end
end
end
Expand Down

0 comments on commit 2d681cc

Please sign in to comment.