ammeter 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -9,4 +9,5 @@ gemfiles/*.lock
9
9
  .rvmrc
10
10
  **/.DS_Store
11
11
  *~
12
- *.swp
12
+ *.swp
13
+ .rbx
@@ -1,4 +1,18 @@
1
1
  script: "bundle exec rake ci"
2
2
  rvm:
3
+ - ruby-head
4
+ - 2.0.0
5
+ - 1.9.3
3
6
  - 1.8.7
4
- - 1.9.3
7
+ - jruby-head
8
+ - jruby-19mode
9
+ - jruby-18mode
10
+ - rbx-19mode
11
+ - rbx-18mode
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: jruby-head
15
+ - rvm: jruby-19mode
16
+ - rvm: jruby-18mode
17
+ - rvm: rbx-19mode
18
+ - rvm: rbx-18mode
data/History.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## Ammeter release history
2
2
 
3
+ ### 0.2.9 / 2013-06-06
4
+
5
+ [full changelog](https://github.com/alexrothenberg/ammeter/compare/v0.2.8...v0.2.9)
6
+
7
+ * Improves `contain` matcher for generated file contents
8
+ * Adds `ensure_current_path` method to GeneratorExampleGroup
9
+
3
10
  ### 0.2.8 / 2012-07-06
4
11
 
5
12
  [full changelog](https://github.com/alexrothenberg/ammeter/compare/v0.2.7...v0.2.8)
data/README.md CHANGED
@@ -1,73 +1,74 @@
1
- # Ammeter [![Build Status](https://secure.travis-ci.org/alexrothenberg/ammeter.png)](http://travis-ci.org/alexrothenberg/ammeter) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/alexrothenberg/ammeter)
1
+ # Ammeter [![Build Status](https://secure.travis-ci.org/alexrothenberg/ammeter.png)](http://travis-ci.org/alexrothenberg/ammeter) [![Code Climate](https://codeclimate.com/github/alexrothenberg/ammeter.png)](https://codeclimate.com/github/alexrothenberg/ammeter) [![Gem Version](https://badge.fury.io/rb/ammeter.png)](http://badge.fury.io/rb/ammeter)
2
+
2
3
 
3
4
  A gem that makes it easy to write specs for your Rails 3 Generators.
4
5
 
5
- RSpec is using ammeter to
6
- [spec](https://github.com/rspec/rspec-rails/blob/master/spec/generators/rspec/model/model_generator_spec.rb)
7
- [its](https://github.com/rspec/rspec-rails/blob/master/spec/generators/rspec/controller/controller_generator_spec.rb)
8
- [own](https://github.com/rspec/rspec-rails/blob/master/spec/generators/rspec/helper/helper_generator_spec.rb)
6
+ RSpec is using ammeter to
7
+ [spec](https://github.com/rspec/rspec-rails/blob/master/spec/generators/rspec/model/model_generator_spec.rb)
8
+ [its](https://github.com/rspec/rspec-rails/blob/master/spec/generators/rspec/controller/controller_generator_spec.rb)
9
+ [own](https://github.com/rspec/rspec-rails/blob/master/spec/generators/rspec/helper/helper_generator_spec.rb)
9
10
  [generators](https://github.com/rspec/rspec-rails/blob/master/spec/generators/rspec/scaffold/scaffold_generator_spec.rb)
10
11
  and we think you may find it useful too.
11
12
 
12
- An [ammeter](http://en.wikipedia.org/wiki/Ammeter) is used to measure electrical current and
13
+ An [ammeter](http://en.wikipedia.org/wiki/Ammeter) is used to measure electrical current and
13
14
  electricity can be produced by a generator.
14
15
 
15
16
  # Example
16
17
 
17
- require 'spec_helper'
18
-
19
- # Generators are not automatically loaded by Rails
20
- require 'generators/rspec/model/model_generator'
21
-
22
- describe Rspec::Generators::ModelGenerator do
23
- # Tell the generator where to put its output (what it thinks of as Rails.root)
24
- destination File.expand_path("../../../../../tmp", __FILE__)
25
- before do
26
- prepare_destination
27
- end
28
-
29
- # using mocks to ensure proper methods are called
30
- # invoke_all - will call all the tasks in the generator
31
- it 'should run all tasks in the generator' do
32
- gen = generator %w(posts)
33
- gen.should_receive :create_model_spec
34
- gen.should_receive :create_fixture_file
35
- capture(:stdout) { gen.invoke_all }
36
- end
37
-
38
- # invoke_task - will call just the named task in the generator
39
- it 'should run a specific tasks in the generator' do
40
- gen = generator %w(posts)
41
- gen.should_receive :create_model_spec
42
- gen.should_not_receive :create_fixture_file
43
- capture(:stdout) { gen.invoke_task :create_model_spec }
44
- end
45
-
46
- # custom matchers make it easy to verify what the generator creates
47
- describe 'the generated files' do
48
- before do
49
- run_generator %w(posts)
50
- end
51
- describe 'the spec' do
52
- # file - gives you the absolute path where the generator will create the file
53
- subject { file('spec/models/posts_spec.rb') }
54
-
55
- # should exist - verifies the file exists
56
- it { should exist }
57
-
58
- # should contain - verifies the file's contents
59
- it { should contain /require 'spec_helper'/ }
60
- it { should contain /describe Posts/ }
61
- end
62
- describe 'the migration' do
63
- subject { file('db/migrate/create_posts.rb') }
64
-
65
- # should be_a_migration - verifies the file exists with a migration timestamp as part of the filename
66
- it { should be_a_migration }
67
- end
68
- end
18
+ ```ruby
19
+ require 'spec_helper'
20
+
21
+ # Generators are not automatically loaded by Rails
22
+ require 'generators/rspec/model/model_generator'
23
+
24
+ describe Rspec::Generators::ModelGenerator do
25
+ # Tell the generator where to put its output (what it thinks of as Rails.root)
26
+ destination File.expand_path("../../../../../tmp", __FILE__)
27
+ before do
28
+ prepare_destination
29
+ end
30
+
31
+ # using mocks to ensure proper methods are called
32
+ # invoke_all - will call all the tasks in the generator
33
+ it 'should run all tasks in the generator' do
34
+ gen = generator %w(posts)
35
+ gen.should_receive :create_model_spec
36
+ gen.should_receive :create_fixture_file
37
+ capture(:stdout) { gen.invoke_all }
38
+ end
39
+
40
+ # invoke_task - will call just the named task in the generator
41
+ it 'should run a specific tasks in the generator' do
42
+ gen = generator %w(posts)
43
+ gen.should_receive :create_model_spec
44
+ gen.should_not_receive :create_fixture_file
45
+ capture(:stdout) { gen.invoke_task :create_model_spec }
46
+ end
47
+
48
+ # custom matchers make it easy to verify what the generator creates
49
+ describe 'the generated files' do
50
+ before do
51
+ run_generator %w(posts)
52
+ end
53
+ describe 'the spec' do
54
+ # file - gives you the absolute path where the generator will create the file
55
+ subject { file('spec/models/posts_spec.rb') }
56
+ # should exist - verifies the file exists
57
+ it { should exist }
58
+
59
+ # should contain - verifies the file's contents
60
+ it { should contain /require 'spec_helper'/ }
61
+ it { should contain /describe Posts/ }
69
62
  end
63
+ describe 'the migration' do
64
+ subject { file('db/migrate/create_posts.rb') }
70
65
 
66
+ # should be_a_migration - verifies the file exists with a migration timestamp as part of the filename
67
+ it { should be_a_migration }
68
+ end
69
+ end
70
+ end
71
+ ```
71
72
 
72
73
  # Contributing
73
74
 
data/Rakefile CHANGED
@@ -32,7 +32,7 @@ def create_gem(gem_name)
32
32
  sh "cp '#{template_folder}/Gemfile' tmp/#{gem_name}"
33
33
  sh "cp '#{template_folder}/#{gem_name}.gemspec' tmp/#{gem_name}"
34
34
  sh "cp '#{template_folder}/Rakefile' tmp/#{gem_name}"
35
- sh "mkdir tmp/#{gem_name}/spec"
35
+ sh "mkdir -p tmp/#{gem_name}/spec"
36
36
  sh "cp '#{template_folder}/spec/spec_helper.rb' tmp/#{gem_name}/spec"
37
37
  Dir.chdir("./tmp/#{gem_name}") do
38
38
  Bundler.clean_system 'bundle install'
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
-
19
+
20
20
  s.add_runtime_dependency 'railties', '>= 3.0'
21
21
  s.add_runtime_dependency 'activesupport', '>= 3.0'
22
22
  s.add_runtime_dependency 'rspec', '>= 2.2'
@@ -30,5 +30,11 @@ Gem::Specification.new do |s|
30
30
  s.add_development_dependency 'jquery-rails', '>= 2.0.2'
31
31
  s.add_development_dependency 'cucumber', '>= 0.10'
32
32
  s.add_development_dependency 'aruba', '>= 0.3'
33
- s.add_development_dependency 'sqlite3', '>= 1'
33
+ case RUBY_PLATFORM
34
+ when 'java'
35
+ s.add_development_dependency 'activerecord-jdbcsqlite3-adapter'
36
+ s.add_development_dependency 'therubyrhino'
37
+ else
38
+ s.add_development_dependency 'sqlite3', '>= 1'
39
+ end
34
40
  end
@@ -0,0 +1,14 @@
1
+ # see https://github.com/cucumber/aruba#jruby-tips
2
+ Aruba.configure do |config|
3
+ config.before_cmd do |cmd|
4
+ set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived
5
+ set_env('JAVA_OPTS', "-d32 #{ENV['JAVA_OPTS']}") # force jRuby to use client JVM for faster startup times
6
+ end
7
+ end if RUBY_PLATFORM == 'java'
8
+
9
+ # MRI 1.8.7 does not define RUBY_ENGINE
10
+ if defined?(RUBY_ENGINE) && %w(jruby rbx).include?(RUBY_ENGINE)
11
+ Before do
12
+ @aruba_timeout_seconds = 30
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  require 'bundler/setup'
2
- require 'ammeter/init'
3
2
  require 'rails'
3
+ require 'ammeter/init'
4
4
 
5
5
  Bundler.require
@@ -25,6 +25,10 @@ module Ammeter
25
25
  def prepare_destination
26
26
  self.test_unit_test_case_delegate.send :prepare_destination
27
27
  end
28
+
29
+ def ensure_current_path
30
+ self.test_unit_test_case_delegate.send :ensure_current_path
31
+ end
28
32
 
29
33
  def initialize_delegate
30
34
  self.test_unit_test_case_delegate = ::Rails::Generators::TestCase.new 'pending'
@@ -49,7 +53,7 @@ module Ammeter
49
53
  end
50
54
 
51
55
  included do
52
- delegate :generator, :run_generator, :destination, :arguments, :to => :'self.class'
56
+ delegate :generator, :run_generator, :destination, :arguments, :ensure_current_path, :to => :'self.class'
53
57
  DELEGATED_METHODS.each do |method|
54
58
  delegate method, :to => :'self.class'
55
59
  end
@@ -1,19 +1,46 @@
1
- RSpec::Matchers.define :contain do |expected_content|
2
- match do |file_path|
3
- @actual_contents = File.new(file_path).read
4
- case expected_content
5
- when String
6
- @actual_contents.include? expected_content
7
- when Regexp
8
- @actual_contents =~ expected_content
9
- end
1
+ RSpec::Matchers.define :contain do |*expected_contents|
2
+ match_for_should do |file_path|
3
+ @actual_contents = File.read(file_path)
4
+ not_found_expectations.empty?
5
+ end
6
+
7
+ match_for_should_not do |file_path|
8
+ @actual_contents = File.read(file_path)
9
+ found_expectations.empty?
10
10
  end
11
-
11
+
12
12
  failure_message_for_should do |file_path|
13
- "expected the file #{file_path} to contain #{expected_content.inspect} but it contained #{@actual_contents.inspect}"
13
+ "expected the file #{file_path} to contain " +
14
+ if expected_contents.many?
15
+ "#{expected_contents.map(&:inspect).to_sentence} but " +
16
+ "#{not_found_expectations.map(&:inspect).to_sentence} #{not_found_expectations.many? ? 'were' : 'was'} not found"
17
+ else
18
+ "#{expected_contents.first.inspect} but it contained #{@actual_contents.inspect}"
19
+ end
14
20
  end
15
-
21
+
16
22
  failure_message_for_should_not do |file_path|
17
- "expected the file #{file_path} to not contain #{expected_content.inspect} but it did"
23
+ "expected the file #{file_path} to not contain " +
24
+ if expected_contents.many?
25
+ "#{expected_contents.map(&:inspect).to_sentence} but " +
26
+ "#{found_expectations.map(&:inspect).to_sentence} #{found_expectations.many? ? 'were' : 'was'} found"
27
+ else
28
+ "#{expected_contents.first.inspect} but it did"
29
+ end
30
+ end
31
+
32
+ define_method :found_expectations do
33
+ @found_expectations ||= expected_contents.select do |expected_content|
34
+ case expected_content
35
+ when String
36
+ @actual_contents.include? expected_content
37
+ when Regexp
38
+ @actual_contents =~ expected_content
39
+ end
40
+ end
41
+ end
42
+
43
+ define_method :not_found_expectations do
44
+ @not_found_expectations ||= expected_contents - found_expectations
18
45
  end
19
46
  end
@@ -1,3 +1,3 @@
1
1
  module Ammeter
2
- VERSION = "0.2.8"
2
+ VERSION = "0.2.9"
3
3
  end
@@ -4,18 +4,19 @@ describe "contain" do
4
4
 
5
5
  context "when the file exists" do
6
6
  let(:contents) { "This file\ncontains\nthis text" }
7
- let(:mock_file) { mock(:read=>contents) }
8
7
 
9
8
  subject { '/some/file/path' }
10
9
  before do
11
- File.stub(:new).with('/some/file/path').and_return(mock_file)
10
+ File.stub(:read).with('/some/file/path').and_return(contents)
12
11
  end
13
12
  it { should contain "This file\ncontains\nthis text" }
14
13
  it { should contain "This file" }
15
14
  it { should contain "this text" }
16
15
  it { should contain /This file/ }
17
16
  it { should contain /this text/ }
17
+ it { should contain "contains", /this text/ }
18
18
  it { should_not contain /something not there/ }
19
+ it { should_not contain /this isn't at the contents/, /neither is this/ }
19
20
  end
20
21
 
21
22
  context "when the file is not there" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ammeter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-06 00:00:00.000000000 Z
12
+ date: 2013-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -237,6 +237,7 @@ files:
237
237
  - features/generator_in_a_gem.feature
238
238
  - features/generator_spec.feature
239
239
  - features/hooking_into_other_generators.feature
240
+ - features/support/aruba_timeout.rb
240
241
  - features/support/env.rb
241
242
  - features/templates/generate_example_app.rb
242
243
  - features/templates/my_rails_gem/Gemfile
@@ -278,7 +279,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
278
279
  version: '0'
279
280
  segments:
280
281
  - 0
281
- hash: -2565557972017694478
282
+ hash: 1076241884620753575
282
283
  required_rubygems_version: !ruby/object:Gem::Requirement
283
284
  none: false
284
285
  requirements:
@@ -287,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
287
288
  version: '0'
288
289
  segments:
289
290
  - 0
290
- hash: -2565557972017694478
291
+ hash: 1076241884620753575
291
292
  requirements: []
292
293
  rubyforge_project:
293
294
  rubygems_version: 1.8.24
@@ -298,6 +299,7 @@ test_files:
298
299
  - features/generator_in_a_gem.feature
299
300
  - features/generator_spec.feature
300
301
  - features/hooking_into_other_generators.feature
302
+ - features/support/aruba_timeout.rb
301
303
  - features/support/env.rb
302
304
  - features/templates/generate_example_app.rb
303
305
  - features/templates/my_rails_gem/Gemfile