ammeter-1.1.4/0000755000175000017500000000000013530106021013674 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/spec/0000755000175000017500000000000013530106021014626 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/spec/spec_helper.rb0000644000175000017500000000112713530106021017445 0ustar utkarsh2102utkarsh2102require 'rails/all' require 'rspec/rails' ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:" module TestApp class Application < Rails::Application config.root = File.dirname(__FILE__) end end require 'ammeter/init' Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} RSpec.configure do |c| c.include MatchesForRSpecRailsSpecs if RSpec::Core::Version::STRING < '3' c.include RSpec2MemoizedHelpersCompatibility end end def stub_file(filename, content) allow(File).to receive(:read).with(filename).and_return(content) end ammeter-1.1.4/spec/support/0000755000175000017500000000000013530106021016342 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/spec/support/mock_generator.rb0000644000175000017500000000041013530106021021661 0ustar utkarsh2102utkarsh2102# Used in generator_example_helpers_spec.rb # set_shell_prompt_responses requires a generator w/ a shell # as an argument. This class defines that generator w/ a shell. class MockGenerator attr_accessor :shell def initialize @shell = Object.new end end ammeter-1.1.4/spec/support/helpers.rb0000644000175000017500000000055013530106021020331 0ustar utkarsh2102utkarsh2102module Helpers def stub_metadata(additional_metadata) stub_metadata = metadata_with(additional_metadata) allow(RSpec::Core::ExampleGroup).to receive(:metadata) { stub_metadata } end def metadata_with(additional_metadata) ::RSpec.describe("example group").metadata.merge(additional_metadata) end RSpec.configure {|c| c.include self} end ammeter-1.1.4/spec/support/memoized_helpers_rspec2compatibility.rb0000644000175000017500000000035713530106021026277 0ustar utkarsh2102utkarsh2102# rspec3 defines this method in RSpec::Core::MemoizedHelpers # see https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/memoized_helpers.rb module RSpec2MemoizedHelpersCompatibility def is_expected expect(subject) end endammeter-1.1.4/spec/support/matchers.rb0000644000175000017500000000104213530106021020472 0ustar utkarsh2102utkarsh2102# Copied from rspec-rails spec/support/matchers.rb module MatchesForRSpecRailsSpecs extend RSpec::Matchers::DSL matcher :be_included_in_files_in do |path| match do |mod| if RSpec::Core::Version::STRING >= '3' stub_metadata( :file_path => "#{path}whatever_spec.rb:15" ) else stub_metadata( :example_group => {:file_path => "#{path}whatever_spec.rb:15"} ) end group = RSpec::Core::ExampleGroup.describe group.included_modules.include?(mod) end end endammeter-1.1.4/spec/ammeter/0000755000175000017500000000000013530106021016260 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/spec/ammeter/rspec/0000755000175000017500000000000013530106021017374 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/spec/ammeter/rspec/generator/0000755000175000017500000000000013530106021021362 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/spec/ammeter/rspec/generator/example/0000755000175000017500000000000013530106021023015 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/spec/ammeter/rspec/generator/example/generator_example_helpers_spec.rb0000644000175000017500000000200713530106021031576 0ustar utkarsh2102utkarsh2102require "spec_helper" module Ammeter::RSpec::Rails describe GeneratorExampleHelpers do include GeneratorExampleHelpers let(:generator) { MockGenerator.new } it "mocks return value of ask to response" do set_shell_prompt_responses(generator, { :ask => "response" }) expect(generator.shell.ask).to eq("response") end context "arguments contain multiple shell commands" do it "mocks return values response for ask and true for yes?" do set_shell_prompt_responses(generator, { :ask => "response", :yes? => true }) expect(generator.shell.ask).to eq("response") expect(generator.shell.yes?).to be true end end context "argument shell command contains an array" do it "mocks sequential return values response1 and response2" do set_shell_prompt_responses(generator, { :ask => ["response1", "response2"] }) expect(generator.shell.ask).to eq("response1") expect(generator.shell.ask).to eq("response2") end end end end ammeter-1.1.4/spec/ammeter/rspec/generator/example/generator_example_group_spec.rb0000644000175000017500000000502013530106021031266 0ustar utkarsh2102utkarsh2102require "spec_helper" module Ammeter::RSpec::Rails describe GeneratorExampleGroup do it { is_expected.to be_included_in_files_in('./spec/generators/') } it { is_expected.to be_included_in_files_in('.\\spec\\generators\\') } let(:group_class) do ::RSpec::Core::ExampleGroup.describe do include GeneratorExampleGroup end end it "adds :type => :generator to the metadata" do expect(group_class.metadata[:type]).to eq(:generator) end describe 'an instance of the group' do let(:group) { group_class.new } describe 'uses the generator as the implicit subject' do let(:generator) { double('generator') } it 'sets a generator as subject' do allow(group).to receive(:generator).and_return(generator) expect(group.subject).to eq generator end end it "allows you to override with explicity subject" do group_class.subject { 'explicit' } expect(group.subject).to eq 'explicit' end it 'allows delegation of destination root to ::Rails::Generators::TestCase' do group.destination '/some/path' expect(group.destination_root).to eq '/some/path' end describe 'working with files' do let(:path_to_gem_root_tmp) { File.expand_path(__FILE__ + '../../../../../../../../tmp') } before do group.destination path_to_gem_root_tmp FileUtils.rm_rf path_to_gem_root_tmp FileUtils.mkdir path_to_gem_root_tmp end it 'should use destination to find relative root file' do expect(group.file('app/model/post.rb')).to eq "#{path_to_gem_root_tmp}/app/model/post.rb" end 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 expect(group.migration_file('db/migrate/create_posts.rb')).to eq "#{path_to_gem_root_tmp}/db/migrate/20111010203337_create_posts.rb" end it 'should stick "TIMESTAMP" in when migration does not exist' do expect(group.migration_file('db/migrate/migration_that_is_not_there.rb')).to eq "#{path_to_gem_root_tmp}/db/migrate/TIMESTAMP_migration_that_is_not_there.rb" end end end end end end ammeter-1.1.4/spec/ammeter/rspec/generator/matchers/0000755000175000017500000000000013530106021023170 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/spec/ammeter/rspec/generator/matchers/have_correct_syntax_spec.rb0000644000175000017500000000536513530106021030612 0ustar utkarsh2102utkarsh2102require 'spec_helper' describe 'have_correct_syntax' do describe 'ruby files' do subject { '/test.rb' } it 'checks if Ruby file has a proper syntax' do stub_file subject, "class SomeClass\n def some_method\n puts 'Hello world!'\n end\nend" expect(subject).to have_correct_syntax end it 'checks if Ruby file has an incorrect syntax' do stub_file subject, "class SomeClass\ndef some_method\nputs 'Hello world!'" expect(subject).to_not have_correct_syntax end end describe 'erb files' do subject { '/test.erb' } it 'checks if simple ERB file has a proper syntax' do stub_file subject, '<% if nonexistent_var == 1 %><% end %>' expect(subject).to have_correct_syntax end it 'checks if simple ERB file has an incorrect syntax' do stub_file subject, '<% if 1 + 1 %> abc' expect(subject).to_not have_correct_syntax end it 'checks if complex ERB file has a proper syntax' do stub_file subject, <<-EOF

<%= application_title %>

<% @elements.each do |element| %> <% end %>
<%= element.id %> <%= element.title %> <%= link_to 'Show', element_path(element) %>
EOF expect(subject).to have_correct_syntax end it 'checks if complex ERB file has an incorrect syntax' do stub_file subject, <<-EOF

This test should fail because I didn't close an each loop.

<% @elements.each do |element| %> <%= element.id %>
EOF expect(subject).to_not have_correct_syntax end end describe 'haml files' do subject { '/test.haml' } it 'checks if simple Haml file has a proper syntax' do stub_file subject, <<-EOF %a{:href => "#"}= @order.id EOF expect(subject).to have_correct_syntax end it 'checks if simple Haml file has an incorrect syntax' do stub_file subject, <<-EOF %a{ EOF expect(subject).to_not have_correct_syntax end it 'checks if complex Haml file has a proper syntax' do stub_file subject, <<-EOF %header %h1= application_title #body %table - @elements.each do |element| %tr %td= element.id %td= element.title %td= link_to 'Show', element_path(element) EOF expect(subject).to have_correct_syntax end it 'checks if complex Haml file has an incorrect syntax' do stub_file subject, <<-EOF #broken-example %p This test should fail because of broken indentation - @elements.each do |element| %tr $td= element.id EOF expect(subject).to_not have_correct_syntax end end end ammeter-1.1.4/spec/ammeter/rspec/generator/matchers/be_a_migration_spec.rb0000644000175000017500000000164313530106021027472 0ustar utkarsh2102utkarsh2102require 'spec_helper' describe "be_a_migration" do let(:migration_files) { ['db/migrate/20110504132601_create_posts.rb', 'db/migrate/20110520132601_create_users.rb'] } before do migration_files.each do |migration_file| allow(File).to receive(:exist?).with(migration_file).and_return(true) end end it 'should find for the migration file adding the filename timestamp for us' do expect(Dir).to receive(:glob).with('db/migrate/[0-9]*_*.rb').and_return(migration_files) expect('db/migrate/create_users.rb').to be_a_migration end it 'should find for the migration file when we know the filename timestamp' do expect('db/migrate/20110504132601_create_posts.rb').to be_a_migration end it 'should know when a migration does not exist' do expect(Dir).to receive(:glob).with('db/migrate/[0-9]*_*.rb').and_return([]) expect('db/migrate/create_comments.rb').to_not be_a_migration end end ammeter-1.1.4/spec/ammeter/rspec/generator/matchers/exist_spec.rb0000644000175000017500000000057413530106021025671 0ustar utkarsh2102utkarsh2102require 'spec_helper' describe "exist" do it 'passes when the file exists' do allow(File).to receive(:exist?).with('/some/file/path').and_return(true) expect('/some/file/path').to exist end it 'fails when the file does not exist' do allow(File).to receive(:exist?).with('/some/file/path').and_return(false) expect('/some/file/path').to_not exist end end ammeter-1.1.4/spec/ammeter/rspec/generator/matchers/have_method_spec.rb0000644000175000017500000000106113530106021027010 0ustar utkarsh2102utkarsh2102require 'spec_helper' describe 'have_method' do let(:contents) { "class SomeClass\n def some_method\n puts 'Hello world!'\n end\nend" } subject { '/some/file/path' } before { allow(File).to receive(:read).with('/some/file/path').and_return(contents) } it { is_expected.to have_method(:some_method) } it { is_expected.to have_method(:some_method).containing("puts 'Hello world!'")} it { is_expected.to_not have_method(:some_method).containing("puts 'Good bye cruel world!' ") } it { is_expected.to_not have_method(:some_other_method) } end ammeter-1.1.4/spec/ammeter/rspec/generator/matchers/contain_spec.rb0000644000175000017500000000174313530106021026167 0ustar utkarsh2102utkarsh2102require 'spec_helper' describe "contain" do context "when the file exists" do let(:contents) { "This file\ncontains\nthis text" } subject { '/some/file/path' } before do allow(File).to receive(:read).with('/some/file/path').and_return(contents) end it { is_expected.to contain "This file\ncontains\nthis text" } it { is_expected.to contain "This file" } it { is_expected.to contain "this text" } it { is_expected.to contain /This file/ } it { is_expected.to contain /this text/ } it { is_expected.to contain "contains", /this text/ } it { is_expected.to_not contain /something not there/ } it { is_expected.to_not contain /this isn't at the contents/, /neither is this/ } end context "when the file is not there" do it 'raises an error when the file does not exist' do expect do expect('some/file/that/does/not/exist').to contain 'something' end.to raise_error /No such file or directory/ end end end ammeter-1.1.4/lib/0000755000175000017500000000000013530106021014442 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/lib/ammeter.rb0000644000175000017500000000027113530106021016421 0ustar utkarsh2102utkarsh2102require 'rails' require 'active_support' # Ensure that Rails has loaded & Initialized if Rails::VERSION::STRING >= "3.1" require 'ammeter/railtie' else require 'ammeter/init' end ammeter-1.1.4/lib/ammeter/0000755000175000017500000000000013530106021016074 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/lib/ammeter/rspec/0000755000175000017500000000000013530106021017210 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/lib/ammeter/rspec/rspec_2_compatibility.rb0000644000175000017500000000104113530106021024017 0ustar utkarsh2102utkarsh2102require 'rspec/expectations' if RSpec::Expectations::Version::STRING < '3' { :match_when_negated => :match_for_should_not, :failure_message => :failure_message_for_should, :failure_message_when_negated => :failure_message_for_should_not }.each do |rspec3_method, rspec2_method| RSpec::Matchers::DSL::Matcher.send :alias_method, rspec3_method, rspec2_method end module RSpec2CoreMemoizedHelpers def is_expected expect(subject) end end RSpec::Core::MemoizedHelpers.extend RSpec2CoreMemoizedHelpers endammeter-1.1.4/lib/ammeter/rspec/generator/0000755000175000017500000000000013530106021021176 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/lib/ammeter/rspec/generator/example.rb0000644000175000017500000000166513530106021023166 0ustar utkarsh2102utkarsh2102require 'rspec/core' require 'ammeter/rspec/generator/example/generator_example_group' require 'ammeter/rspec/generator/example/generator_example_helpers' RSpec::configure do |c| def c.escaped_path(*parts) Regexp.compile(parts.join('[\\\/]') + '[\\\/]') end generator_path_regex = c.escaped_path(%w[spec generators]) if RSpec::Core::Version::STRING >= '3' c.include Ammeter::RSpec::Rails::GeneratorExampleHelpers, :type => :generator c.include Ammeter::RSpec::Rails::GeneratorExampleGroup, :type => :generator, :file_path => lambda { |file_path, metadata| metadata[:type].nil? && generator_path_regex =~ file_path } else #rspec2 c.include Ammeter::RSpec::Rails::GeneratorExampleHelpers, :type => :generator c.include Ammeter::RSpec::Rails::GeneratorExampleGroup, :type => :generator, :example_group => { :file_path => generator_path_regex } end end ammeter-1.1.4/lib/ammeter/rspec/generator/example/0000755000175000017500000000000013530106021022631 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/lib/ammeter/rspec/generator/example/generator_example_helpers.rb0000644000175000017500000000207013530106021030400 0ustar utkarsh2102utkarsh2102require 'rails/generators' require 'active_support/core_ext' module Ammeter module RSpec module Rails # Delegates to Rails::Generators::TestCase to work with RSpec. module GeneratorExampleHelpers # Sets return values for basic shell commands (ex. ask, yes?, no?). # Does this by mocking return values using RSpec's `and_return` method # # ===== Parameters ===== # Generator w/ @shell attribute # Hash { command_name: input_value, ask: "Testing", yes?: true } # The values for each element in the hash can be set as an array as well. # This will allow for different return values upon each call. # # ex. set_shell_prompt_responses(generator, { yes?: [true, false] }) # would respond with true to the first yes? call, but false to the second def set_shell_prompt_responses(generator, command_args={}) command_args.each do |k,v| allow(generator.shell).to receive(k.to_sym).and_return(*v) end end end end end end ammeter-1.1.4/lib/ammeter/rspec/generator/example/generator_example_group.rb0000644000175000017500000000603513530106021030077 0ustar utkarsh2102utkarsh2102require 'rails/generators' require 'active_support/core_ext' require 'tmpdir' require 'fileutils' module Ammeter module RSpec module Rails # Delegates to Rails::Generators::TestCase to work with RSpec. module GeneratorExampleGroup extend ActiveSupport::Concern include ::RSpec::Rails::RailsExampleGroup DELEGATED_METHODS = [:destination_root, :current_path, :generator_class] module ClassMethods mattr_accessor :test_unit_test_case_delegate delegate :default_arguments, :to => :'self.test_unit_test_case_delegate' DELEGATED_METHODS.each do |method| delegate method, :to => :'self.test_unit_test_case_delegate' end delegate :destination, :arguments, :to => ::Rails::Generators::TestCase def prepare_destination self.test_unit_test_case_delegate.send :prepare_destination end def ensure_current_path self.test_unit_test_case_delegate.send :ensure_current_path end def initialize_delegate self.test_unit_test_case_delegate = ::Rails::Generators::TestCase.new 'pending' self.test_unit_test_case_delegate.class.tests(described_class) @generator = nil end def generator(given_args=self.default_arguments, config={}) @generator ||= begin args, opts = Thor::Options.split(given_args) self.test_unit_test_case_delegate.generator(args, opts, config) end end def run_generator(given_args=self.default_arguments, config={}) OutputCapturer.capture(:stdout) { generator(given_args, config).invoke_all } end end def invoke_task name OutputCapturer.capture(:stdout) { generator.invoke_task(generator_class.all_tasks[name.to_s]) } end included do delegate :generator, :run_generator, :destination, :arguments, :ensure_current_path, :to => :'self.class' DELEGATED_METHODS.each do |method| delegate method, :to => :'self.class' end def prepare_destination self.class.send :prepare_destination end ::Rails::Generators::TestCase.destination File.expand_path('ammeter', Dir.tmpdir) initialize_delegate before do self.class.initialize_delegate prepare_destination end after do # ensure_current_path end metadata[:type] = :generator end def file relative File.expand_path(relative, destination_root) end def migration_file relative file_path = file(relative) 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 def subject generator end end end end end ammeter-1.1.4/lib/ammeter/rspec/generator/matchers/0000755000175000017500000000000013530106021023004 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/lib/ammeter/rspec/generator/matchers/contain.rb0000644000175000017500000000277313530106021024775 0ustar utkarsh2102utkarsh2102RSpec::Matchers.define :contain do |*expected_contents| match do |file_path| @actual_contents = File.read(file_path) not_found_expectations.empty? end match_when_negated do |file_path| @actual_contents = File.read(file_path) found_expectations.empty? end failure_message do |file_path| "expected the file #{file_path} to contain " + if expected_contents.many? "#{expected_contents.map(&:inspect).to_sentence} but " + "#{not_found_expectations.map(&:inspect).to_sentence} #{not_found_expectations.many? ? 'were' : 'was'} not found" else "#{expected_contents.first.inspect} but it contained #{@actual_contents.inspect}" end end failure_message_when_negated do |file_path| "expected the file #{file_path} to not contain " + if expected_contents.many? "#{expected_contents.map(&:inspect).to_sentence} but " + "#{found_expectations.map(&:inspect).to_sentence} #{found_expectations.many? ? 'were' : 'was'} found" else "#{expected_contents.first.inspect} but it did" end end define_method :found_expectations do @found_expectations ||= expected_contents.select do |expected_content| case expected_content when String @actual_contents.include? expected_content when Regexp @actual_contents =~ expected_content end end end define_method :not_found_expectations do @not_found_expectations ||= expected_contents - found_expectations end end ammeter-1.1.4/lib/ammeter/rspec/generator/matchers/exist.rb0000644000175000017500000000013513530106021024464 0ustar utkarsh2102utkarsh2102RSpec::Matchers.define :exist do match do |file_path| File.exist?(file_path) end end ammeter-1.1.4/lib/ammeter/rspec/generator/matchers/be_a_migration.rb0000644000175000017500000000061213530106021026267 0ustar utkarsh2102utkarsh2102RSpec::Matchers.define :be_a_migration do match do |file_path| dirname, file_name = File.dirname(file_path), File.basename(file_path) if file_name =~ /\d+_.*\.rb/ migration_file_path = file_path else migration_file_path = Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}$/).first end migration_file_path && File.exist?(migration_file_path) end end ammeter-1.1.4/lib/ammeter/rspec/generator/matchers/have_correct_syntax.rb0000644000175000017500000000213413530106021027403 0ustar utkarsh2102utkarsh2102RSpec::Matchers.define :have_correct_syntax do match do |file_path| source = File.read(file_path) extension = File.extname(file_path) case extension when '.rb', '.rake' check_ruby_syntax(source) when '.rhtml', '.erb' check_erb_syntax(source) when '.haml' check_haml_syntax(source) else raise "Checking syntax for #{extension} files is not yet supported" end end define_method :check_ruby_syntax do |code| begin eval('__crash_me__;' + code) rescue SyntaxError false rescue NameError true end end define_method :check_erb_syntax do |code| require 'action_view' require 'ostruct' begin view = ActionView::Template::Handlers::ERB.call(OpenStruct.new(:source => code)) eval('__crash_me__; ' + view) rescue SyntaxError false rescue NameError true end end define_method :check_haml_syntax do |code| require 'haml' begin Haml::Engine.new(code) rescue Haml::SyntaxError false rescue NameError true end end end ammeter-1.1.4/lib/ammeter/rspec/generator/matchers/have_method.rb0000644000175000017500000000047213530106021025617 0ustar utkarsh2102utkarsh2102RSpec::Matchers.define :have_method do |method| chain :containing do |content| @method_content = content.strip end match do |file_path| content = File.read(file_path) content =~ /(\s+)def #{method}(\(.+\))?(.*?)\n\1end/m && (@method_content.nil? ? true : $3.include?(@method_content)) end end ammeter-1.1.4/lib/ammeter/rspec/generator/matchers.rb0000644000175000017500000000042413530106021023331 0ustar utkarsh2102utkarsh2102require 'ammeter/rspec/generator/matchers/be_a_migration' require 'ammeter/rspec/generator/matchers/contain' require 'ammeter/rspec/generator/matchers/exist' require 'ammeter/rspec/generator/matchers/have_method' require 'ammeter/rspec/generator/matchers/have_correct_syntax' ammeter-1.1.4/lib/ammeter/version.rb0000644000175000017500000000004713530106021020107 0ustar utkarsh2102utkarsh2102module Ammeter VERSION = "1.1.4" end ammeter-1.1.4/lib/ammeter/railtie.rb0000644000175000017500000000023413530106021020051 0ustar utkarsh2102utkarsh2102module Ammeter class Railtie < Rails::Railtie initializer 'my_engine.interact_with_routes' do |app| require 'ammeter/init.rb' end end end ammeter-1.1.4/lib/ammeter/init.rb0000644000175000017500000000064113530106021017365 0ustar utkarsh2102utkarsh2102require 'rspec/core' require 'rspec/rails' if RSpec::Core::Version::STRING < '3' require 'ammeter/rspec/rspec_2_compatibility' # if rspec2 end require 'rails' require 'ammeter/output_capturer.rb' require 'ammeter/rspec/generator/example.rb' require 'ammeter/rspec/generator/matchers.rb' if Rails.respond_to?(:application) && Rails.application.respond_to?(:load_generators) Rails.application.load_generators end ammeter-1.1.4/lib/ammeter/output_capturer.rb0000644000175000017500000000140313530106021021664 0ustar utkarsh2102utkarsh2102module Ammeter class OutputCapturer # Is this thread safe!?!? # This won't work with sub-processes def self.capture(io, &block) case io when :stdout capture_stdout(&block) when :stderr capture_stderr(&block) else raise "Unknown IO #{io}" end end def self.capture_stdout(&block) captured_stream = StringIO.new orginal_io, $stdout = $stdout, captured_stream block.call captured_stream.string ensure $stdout = orginal_io end def self.capture_stderr(&block) captured_stream = StringIO.new orginal_io, $stderr = $stderr, captured_stream block.call captured_stream.string ensure $stderr = orginal_io end end endammeter-1.1.4/Rakefile0000644000175000017500000000435613530106021015351 0ustar utkarsh2102utkarsh2102require 'bundler' require 'bundler/setup' Bundler::GemHelper.install_tasks require 'rdoc/task' require 'rspec/core' require 'rspec/core/rake_task' require 'cucumber/rake/task' task :cleanup_rcov_files do rm_rf 'coverage.data' end desc "Run all examples" RSpec::Core::RakeTask.new(:spec) do |t| t.rspec_opts = %w[--color] end Cucumber::Rake::Task.new(:cucumber) task :ensure_bundler_11 do raise 'Bundler 1.1 is a development dependency to build ammeter. Please upgrade bundler.' unless Bundler::VERSION >= '1.1' end def create_gem(gem_name) template_folder = "features/templates/#{gem_name}" Dir.chdir("./tmp") do sh "yes | bundle gem -t rspec #{gem_name}" end sh "cp '#{template_folder}/Gemfile' tmp/#{gem_name}" sh "cp '#{template_folder}/#{gem_name}.gemspec' tmp/#{gem_name}" sh "cp '#{template_folder}/Rakefile' tmp/#{gem_name}" sh "mkdir -p tmp/#{gem_name}/spec" sh "cp '#{template_folder}/spec/spec_helper.rb' tmp/#{gem_name}/spec" Dir.chdir("./tmp/#{gem_name}") do Bundler.clean_system 'bundle install' end end namespace :generate do desc "generate a fresh app with rspec installed" task :app => :ensure_bundler_11 do |t| sh "bundle exec rails new ./tmp/example_app -m 'features/templates/generate_example_app.rb' --skip-test-unit" sh "cp 'features/templates/rspec.rake' ./tmp/example_app/lib/tasks" Dir.chdir("./tmp/example_app/") do Bundler.clean_system 'bundle install' Bundler.clean_system 'rake db:migrate' Bundler.clean_system 'rails g rspec:install' Bundler.clean_system 'spring stop' end end desc "generate a fresh gem that depends on railties" task :railties_gem => :ensure_bundler_11 do |t| create_gem('my_railties_gem') end desc "generate a fresh gem that depends on rails" task :rails_gem => :ensure_bundler_11 do |t| create_gem('my_rails_gem') end end task :generate => [:'generate:app', :'generate:railties_gem', :'generate:rails_gem'] namespace :clobber do desc "clobber the generated app" task :app do rm_rf "tmp/example_app" end task :gem do rm_rf "tmp/my_railties_gem" rm_rf "tmp/my_rails_gem" end end task :clobber => [:'clobber:app', :'clobber:gem'] task :ci => [:spec, :clobber, :generate, :cucumber] task :default => :ci ammeter-1.1.4/LICENSE.txt0000644000175000017500000000204213530106021015515 0ustar utkarsh2102utkarsh2102Copyright (c) 2011 Alex Rothenberg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.ammeter-1.1.4/ammeter.gemspec0000644000175000017500000000316313530106021016676 0ustar utkarsh2102utkarsh2102# -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) require "ammeter/version" Gem::Specification.new do |s| s.name = "ammeter" s.version = Ammeter::VERSION s.platform = Gem::Platform::RUBY s.authors = ["Alex Rothenberg"] s.email = ["alex@alexrothenberg.com"] s.homepage = "" s.summary = %q{Write specs for your Rails 3+ generators} s.description = %q{Write specs for your Rails 3+ generators} s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] s.add_runtime_dependency 'railties', '>= 3.0' s.add_runtime_dependency 'activesupport', '>= 3.0' s.add_runtime_dependency 'rspec-rails', '>= 2.2' s.add_development_dependency 'rspec', '>= 2.2' s.add_development_dependency 'rails', '>= 3.1' s.add_development_dependency 'uglifier', '>= 1.2.4' s.add_development_dependency 'rake', '>= 0.9.2.2' s.add_development_dependency 'coffee-rails', '>= 3.2.2' s.add_development_dependency 'sass-rails', '>= 3.2.5' s.add_development_dependency 'jquery-rails', '>= 2.0.2' s.add_development_dependency 'haml-rails', '>= 0.4' s.add_development_dependency 'cucumber', '>= 0.10' s.add_development_dependency 'aruba', '>= 0.3' case RUBY_PLATFORM when 'java' s.add_development_dependency 'activerecord-jdbcsqlite3-adapter' s.add_development_dependency 'therubyrhino' else s.add_development_dependency 'sqlite3', '>= 1' end end ammeter-1.1.4/README.md0000644000175000017500000001013113530106021015147 0ustar utkarsh2102utkarsh2102# 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) A gem that makes it easy to write specs for your Rails 3 Generators. RSpec is using ammeter to [spec](https://github.com/rspec/rspec-rails/blob/master/spec/generators/rspec/model/model_generator_spec.rb) [its](https://github.com/rspec/rspec-rails/blob/master/spec/generators/rspec/controller/controller_generator_spec.rb) [own](https://github.com/rspec/rspec-rails/blob/master/spec/generators/rspec/helper/helper_generator_spec.rb) [generators](https://github.com/rspec/rspec-rails/blob/master/spec/generators/rspec/scaffold/scaffold_generator_spec.rb) and we think you may find it useful too. An [ammeter](http://en.wikipedia.org/wiki/Ammeter) is used to measure electrical current and electricity can be produced by a generator. # Example ```ruby require 'spec_helper' # Generators are not automatically loaded by Rails require 'generators/rspec/model/model_generator' describe Rspec::Generators::ModelGenerator, :type => :generator do # Tell the generator where to put its output (what it thinks of as Rails.root) destination File.expand_path("../../../../../tmp", __FILE__) before do prepare_destination end # using mocks to ensure proper methods are called # invoke_all - will call all the tasks in the generator it 'should run all tasks in the generator' do gen = generator %w(posts) gen.should_receive :create_model_spec gen.should_receive :create_fixture_file capture(:stdout) { gen.invoke_all } end # invoke_task - will call just the named task in the generator it 'should run a specific tasks in the generator' do gen = generator %w(posts) gen.should_receive :create_model_spec gen.should_not_receive :create_fixture_file capture(:stdout) { gen.invoke_task :create_model_spec } end # custom matchers make it easy to verify what the generator creates describe 'the generated files' do before do run_generator %w(posts) end describe 'the spec' do # file - gives you the absolute path where the generator will create the file subject { file('spec/models/posts_spec.rb') } # is_expected_to exist - verifies the file exists it { is_expected_to exist } # is_expected_to contain - verifies the file's contents it { is_expected_to contain /require 'spec_helper'/ } it { is_expected_to contain /describe Posts/ } end describe 'the migration' do subject { migration_file('db/migrate/create_posts.rb') } # is_expected_to be_a_migration - verifies the file exists with a migration timestamp as part of the filename it { is_expected_to exist } it { is_expected_to contain /create_table/ } end end end ``` # Available matchers - `exist` - verifies the file exists - `contain` - verifies the file's contents - `be_a_migration` - verifies the file exists with a migration timestamp as part of the filename - `have_method` - verifies the file (or a class withing it) implements a method - `have_correct_syntax` - verifies the file has correct syntax and is not broken (works for .rb, .erb and .haml files) # Contributing * Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet * Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it * Fork the project * Start a feature/bugfix branch * Commit and push until you are happy with your contribution * Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally. * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. # Copyright Copyright © 2011 Alex Rothenberg. See LICENSE.txt for further details. ammeter-1.1.4/features/0000755000175000017500000000000013530106021015512 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/features/generator_spec.feature0000644000175000017500000001675313530106021022103 0ustar utkarsh2102utkarsh2102@example_app Feature: generator spec Generator specs live in spec/generators. In order to access the generator's methods you can call them on the "generator" object. Background: A simple generator 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.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.erb" with: """ <%= 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 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 'can run a reverse migration' do FileUtils.mkdir_p(File.dirname(subject)) # File.write is not in 1.8.7 use File.open File.open(subject, 'w') do |f| f.write "test file" end expect(subject).to exist run_generator %w(my_dir --someone Alex), :behavior => :revoke expect(subject).not_to exist end end end """ When I run `rake spec` 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" require 'generators/awesome/awesome_generator' describe AwesomeGenerator do arguments %w(another_dir) before { invoke_task :create_awesomeness } describe 'public/another_dir/awesome.html' do subject { file('public/another_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/another_dir/lame.html' do subject { file('public/another_dir/lame.html') } it { should_not exist } end end """ When I run `rake spec` Then the output should contain "4 examples, 0 failures" Scenario: A spec with some failures shows nice error messages 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 subject { file('public/my_dir/awesome.html') } it { expect(subject).to_not contain 'This is an awesome file' } it { expect(subject).to contain 'This text is not in the file' } it { expect(subject).to_not exist } end describe 'public/my_dir/non_existent.html' do subject { file('public/my_dir/non_existent.html') } it { expect(subject).to exist } end describe 'db/migrate/non_existent_migration.rb' do subject { migration_file('db/migrate/non_existent_migration.rb') } it { expect(subject).to exist } end end """ When I run `rake spec` Then the output should contain "5 examples, 5 failures" And the output should contain: """ /public/my_dir/awesome.html to not contain "This is an awesome file" but it did """ And the output should contain: """ /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: """ /public/my_dir/awesome.html" not to exist """ And the output should contain: """ /public/my_dir/non_existent.html" to exist """ And the output should contain: """ db/migrate/TIMESTAMP_non_existent_migration.rb" to exist """ Scenario: Can specify arguments separately from running the generator Given a file named "spec/generators/awesome_generator_spec.rb" with: """ require "rails_helper" require 'generators/awesome/awesome_generator' describe AwesomeGenerator do arguments %w(my_dir --super) before { generator.invoke_all } describe 'public/my_dir/super_awesome.html' do subject { file('public/my_dir/super_awesome.html') } it { expect(subject).to exist } end describe 'public/my_dir/super_lame.html' do subject { file('public/my_dir/super_lame.html') } it { expect(subject).to exist } end end """ When I run `rake spec` Then the output should contain "2 examples, 0 failures" Scenario: A generator that creates a migration Given a file named "spec/generators/a_migration_spec.rb" with: """ require "rails_helper" require 'rails/generators/active_record/migration/migration_generator' describe ActiveRecord::Generators::MigrationGenerator do before { run_generator %w(create_posts) } subject { migration_file('db/migrate/create_posts.rb') } it { expect(subject).to exist } it { expect(subject).to be_a_migration } it { expect(subject).to contain 'class CreatePosts < ActiveRecord::Migration' } end """ When I run `rake spec` Then the output should contain "3 examples, 0 failures" Scenario: Can tell the generator where to put its files Given a file named "spec/generators/awesome_generator_spec.rb" with: """ require "rails_helper" require 'generators/awesome/awesome_generator' describe AwesomeGenerator do destination Rails.root + 'tmp/generated_files' before { run_generator %w(my_dir --super) } describe 'public/my_dir/super_awesome.html' do subject { file('public/my_dir/super_awesome.html') } it { expect(subject).to eq "#{Rails.root}/tmp/generated_files/public/my_dir/super_awesome.html" } it { expect(subject).to exist } end end """ When I run `rake spec` Then the output should contain "2 examples, 0 failures" ammeter-1.1.4/features/support/0000755000175000017500000000000013530106021017226 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/features/support/env.rb0000644000175000017500000000322213530106021020342 0ustar utkarsh2102utkarsh2102require 'aruba/cucumber' Before do if RUBY_VERSION == "1.9.3" @aruba_timeout_seconds = 60 else @aruba_timeout_seconds = 30 end end def aruba_path(file_or_dir, source_foldername) File.expand_path("../../../#{file_or_dir.sub(source_foldername,'aruba')}", __FILE__) end def example_app_path(file_or_dir) File.expand_path("../../../#{file_or_dir}", __FILE__) end def write_symlink(file_or_dir, source_foldername, filename=nil) source = example_app_path(file_or_dir) target = aruba_path(file_or_dir, source_foldername) target = File.join(File.dirname(target), filename) if filename system "ln -s #{source} #{target}" end def copy_to_aruba_from(gem_or_app_name) steps %Q{ Given a directory named "spec" } rspec_version = ENV['RSPEC_VERSION'] rspec_major_version = (rspec_version && rspec_version != 'master') ? rspec_version.scan(/\d+/).first : '3' Dir["tmp/#{gem_or_app_name}/*"].each do |file_or_dir| if !(file_or_dir =~ /\/spec$/) write_symlink(file_or_dir, gem_or_app_name) end end write_symlink("tmp/#{gem_or_app_name}/spec/spec_helper.rb", gem_or_app_name) if rspec_major_version == '2' # rspec 2.x does not create rails_helper.rb so we create a symlink to avoid cluttering tests write_symlink("tmp/#{gem_or_app_name}/spec/spec_helper.rb", gem_or_app_name, 'rails_helper.rb') elsif rspec_major_version == '3' write_symlink("tmp/#{gem_or_app_name}/spec/rails_helper.rb", gem_or_app_name) end end Before '@example_app' do copy_to_aruba_from('example_app') end Before '@railties_gem' do copy_to_aruba_from('my_railties_gem') end Before '@rails_gem' do copy_to_aruba_from('my_rails_gem') end ammeter-1.1.4/features/support/aruba_timeout.rb0000644000175000017500000000055513530106021022420 0ustar utkarsh2102utkarsh2102# see https://github.com/cucumber/aruba#jruby-tips Aruba.configure do |config| config.before_cmd do |cmd| set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived set_env('JAVA_OPTS', "-d32 #{ENV['JAVA_OPTS']}") # force jRuby to use client JVM for faster startup times end end if RUBY_PLATFORM == 'java' ammeter-1.1.4/features/generator_in_a_gem.feature0000644000175000017500000000600413530106021022673 0ustar utkarsh2102utkarsh2102Feature: Gems can contain generators Within a Gem Rails may often not be loaded (but railties is) We should still be able to write a spec for these generators @railties_gem Scenario: A generator with "railties" dependency 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 def create_awesomeness template 'awesome.html', File.join('public', name, "#{"super_" if options[:super]}awesome.html") end end """ And a file named "lib/generators/awesome/templates/awesome.html" with: """ This is an awesome file """ And a file named "spec/generators/awesome_generator_spec.rb" with: """ require "spec_helper" require 'generators/awesome/awesome_generator' describe AwesomeGenerator do before { run_generator %w(my_dir) } 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 end """ When I run `rake spec` Then the output should contain "3 examples, 0 failures" @rails_gem Scenario: A generator that uses "hook_for" Given a file named "lib/generators/resourceful/resourceful_generator.rb" with: """ class ResourcefulGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) class_option :super, :type => :boolean, :default => false hook_for :orm, :in => :rails, :as => :model, :required => true def create_resourceful_controller template 'controller.rb', File.join('app/controllers', "#{plural_file_name}_controller.rb") end end """ And a file named "lib/generators/resourceful/templates/controller.rb" with: """ class <%= class_name.pluralize %>Controller < ResourcefulController end """ And a file named "spec/generators/resourceful_generator_spec.rb" with: """ require "spec_helper" require 'generators/resourceful/resourceful_generator' describe ResourcefulGenerator do before { run_generator %w(post) } describe 'app/controller/posts_controller.rb' do subject { file('app/controllers/posts_controller.rb') } it { expect(subject).to exist } it { expect(subject).to contain 'class PostsController < ResourcefulController' } end describe 'app/models/post.rb' do subject { file('app/models/post.rb') } it { expect(subject).to exist } it { expect(subject).to contain 'class Post < ' } end end """ When I run `rake spec` Then the output should contain "4 examples, 0 failures" ammeter-1.1.4/features/templates/0000755000175000017500000000000013530106021017510 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/features/templates/my_rails_gem/0000755000175000017500000000000013530106021022157 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/features/templates/my_rails_gem/spec/0000755000175000017500000000000013530106021023111 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/features/templates/my_rails_gem/spec/spec_helper.rb0000644000175000017500000000071213530106021025727 0ustar utkarsh2102utkarsh2102require 'bundler/setup' require 'rails/all' ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:" begin # This prevents 'uninitialized constant Jquery::Rails::Railtie::PROTOTYPE_JS (NameError)' require 'jquery/rails' rescue LoadError end module MyRailsGem module TestApp class Application < Rails::Application config.root = File.dirname(__FILE__) end end end require 'ammeter/init' Bundler.require ammeter-1.1.4/features/templates/my_rails_gem/Rakefile0000644000175000017500000000030113530106021023616 0ustar utkarsh2102utkarsh2102#!/usr/bin/env rake require "bundler/gem_tasks" require 'rspec' require 'rspec/core/rake_task' desc "Run all examples" RSpec::Core::RakeTask.new(:spec) do |t| t.rspec_opts = %w[--color] end ammeter-1.1.4/features/templates/my_rails_gem/my_rails_gem.gemspec0000644000175000017500000000130013530106021026165 0ustar utkarsh2102utkarsh2102# -*- encoding: utf-8 -*- require File.expand_path('../lib/my_rails_gem/version', __FILE__) Gem::Specification.new do |gem| gem.authors = ["Alex Rothenberg"] gem.email = ["alex@alexrothenberg.com"] gem.description = %q{TODO: Write a gem description} gem.summary = %q{TODO: Write a gem summary} gem.homepage = "" gem.files = `git ls-files`.split($\) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.name = "my_rails_gem" gem.require_paths = ["lib"] gem.version = MyRailsGem::VERSION gem.add_runtime_dependency 'rails', '>= 3.2' end ammeter-1.1.4/features/templates/my_rails_gem/Gemfile0000644000175000017500000000233713530106021023457 0ustar utkarsh2102utkarsh2102source 'https://rubygems.org' rspec_version = ENV['RSPEC_VERSION'] rspec_major_version = (rspec_version && rspec_version != 'master') ? rspec_version.scan(/\d+/).first : '3' if rspec_version == 'master' gem "rspec-rails", :git => 'git://github.com/rspec/rspec-rails.git' gem "rspec", :git => 'git://github.com/rspec/rspec.git' gem "rspec-core", :git => 'git://github.com/rspec/rspec-core.git' gem "rspec-expectations", :git => 'git://github.com/rspec/rspec-expectations.git' gem "rspec-mocks", :git => 'git://github.com/rspec/rspec-mocks.git' gem "rspec-collection_matchers", :git => 'git://github.com/rspec/rspec-collection_matchers.git' gem "rspec-support", :git => 'git://github.com/rspec/rspec-support.git' else gem 'rspec-rails', rspec_version gem 'rspec', rspec_version end if rspec_major_version == '2' || RUBY_VERSION.to_f < 1.9 gem 'rails', '~> 3.2.0' # Execjs is causing problems on 1.8.7 gem 'execjs', '~> 2.0.0' elsif rspec_major_version == '3' gem 'rails', '>= 4.1' else raise "rspec version #{rspec_version} is not supported" end # Specify your gem's dependencies in my_gem.gemspec gemspec # we cannot add a development dependency with a path to my_gem.gemspec gem 'ammeter', :path => '../..' ammeter-1.1.4/features/templates/rspec.rake0000644000175000017500000000013013530106021021462 0ustar utkarsh2102utkarsh2102require 'rspec/core/rake_task' desc "Run all examples" RSpec::Core::RakeTask.new(:spec)ammeter-1.1.4/features/templates/generate_example_app.rb0000644000175000017500000000172313530106021024205 0ustar utkarsh2102utkarsh2102rspec_version = ENV['RSPEC_VERSION'] rspec_major_version = (rspec_version && rspec_version != 'master') ? rspec_version.scan(/\d+/).first : '3' if rspec_version == 'master' gem "rspec-rails", :git => 'git://github.com/rspec/rspec-rails.git' gem "rspec", :git => 'git://github.com/rspec/rspec.git' gem "rspec-core", :git => 'git://github.com/rspec/rspec-core.git' gem "rspec-expectations", :git => 'git://github.com/rspec/rspec-expectations.git' gem "rspec-mocks", :git => 'git://github.com/rspec/rspec-mocks.git' gem "rspec-collection_matchers", :git => 'git://github.com/rspec/rspec-collection_matchers.git' gem "rspec-support", :git => 'git://github.com/rspec/rspec-support.git' else gem 'rspec-rails', rspec_version gem 'rspec', rspec_version end gem "i18n", '< 0.7.0' if RUBY_VERSION < '1.9.3' gem 'ammeter', :path=>'../..' if defined?(Rails) && Rails::VERSION::STRING.to_f < 4 # Execjs is causing problems on 1.8.7 gem 'execjs', '~> 2.0.0' end ammeter-1.1.4/features/templates/my_railties_gem/0000755000175000017500000000000013530106021022661 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/features/templates/my_railties_gem/spec/0000755000175000017500000000000013530106021023613 5ustar utkarsh2102utkarsh2102ammeter-1.1.4/features/templates/my_railties_gem/spec/spec_helper.rb0000644000175000017500000000025313530106021026431 0ustar utkarsh2102utkarsh2102require 'bundler/setup' require 'rails/all' require 'ammeter/init' Bundler.require ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:" ammeter-1.1.4/features/templates/my_railties_gem/my_railties_gem.gemspec0000644000175000017500000000131413530106021027376 0ustar utkarsh2102utkarsh2102# -*- encoding: utf-8 -*- require File.expand_path('../lib/my_railties_gem/version', __FILE__) Gem::Specification.new do |gem| gem.authors = ["Alex Rothenberg"] gem.email = ["alex@alexrothenberg.com"] gem.description = %q{TODO: Write a gem description} gem.summary = %q{TODO: Write a gem summary} gem.homepage = "" gem.files = `git ls-files`.split($\) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.name = "my_railties_gem" gem.require_paths = ["lib"] gem.version = MyRailtiesGem::VERSION gem.add_runtime_dependency 'railties', '>= 3.2' end ammeter-1.1.4/features/templates/my_railties_gem/Rakefile0000644000175000017500000000030113530106021024320 0ustar utkarsh2102utkarsh2102#!/usr/bin/env rake require "bundler/gem_tasks" require 'rspec' require 'rspec/core/rake_task' desc "Run all examples" RSpec::Core::RakeTask.new(:spec) do |t| t.rspec_opts = %w[--color] end ammeter-1.1.4/features/templates/my_railties_gem/Gemfile0000644000175000017500000000234613530106021024161 0ustar utkarsh2102utkarsh2102source 'https://rubygems.org' rspec_version = ENV['RSPEC_VERSION'] rspec_major_version = (rspec_version && rspec_version != 'master') ? rspec_version.scan(/\d+/).first : '3' if rspec_version == 'master' gem "rspec-rails", :git => 'git://github.com/rspec/rspec-rails.git' gem "rspec", :git => 'git://github.com/rspec/rspec.git' gem "rspec-core", :git => 'git://github.com/rspec/rspec-core.git' gem "rspec-expectations", :git => 'git://github.com/rspec/rspec-expectations.git' gem "rspec-mocks", :git => 'git://github.com/rspec/rspec-mocks.git' gem "rspec-collection_matchers", :git => 'git://github.com/rspec/rspec-collection_matchers.git' gem "rspec-support", :git => 'git://github.com/rspec/rspec-support.git' else gem 'rspec-rails', rspec_version gem 'rspec', rspec_version end if rspec_major_version == '2' || RUBY_VERSION.to_f < 1.9 gem 'railties', '~> 3.2.0' # Execjs is causing problems on 1.8.7 #gem 'execjs', '~> 2.0.0' elsif rspec_major_version == '3' gem 'railties', '>= 4.1' else raise "rspec version #{rspec_version} is not supported" end # Specify your gem's dependencies in my_gem.gemspec gemspec # we cannot add a development dependency with a path to my_gem.gemspec gem 'ammeter', :path => '../..' ammeter-1.1.4/features/hooking_into_other_generators.feature0000644000175000017500000000345013530106021025212 0ustar utkarsh2102utkarsh2102@example_app Feature: generator spec Generator specs live in spec/generators. In order to access the generator's methods you can call them on the "generator" object. Background: A generator that uses "hook_for" Given a file named "lib/generators/resourceful/resourceful_generator.rb" with: """ class ResourcefulGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) class_option :super, :type => :boolean, :default => false hook_for :orm, :in => :rails, :as => :model, :required => true def create_resourceful_controller template 'controller.rb', File.join('app/controllers', "#{plural_file_name}_controller.rb") end end """ And a file named "lib/generators/resourceful/templates/controller.rb" with: """ class <%= class_name.pluralize %>Controller < ResourcefulController end """ Scenario: A spec that runs the entire generator Given a file named "spec/generators/resourceful_generator_spec.rb" with: """ require "rails_helper" require 'generators/resourceful/resourceful_generator' describe ResourcefulGenerator do before { run_generator %w(post) } describe 'app/controller/posts_controller.rb' do subject { file('app/controllers/posts_controller.rb') } it { expect(subject).to exist } it { expect(subject).to contain 'class PostsController < ResourcefulController' } end describe 'app/models/post.rb' do subject { file('app/models/post.rb') } it { expect(subject).to exist } it { expect(subject).to contain 'class Post < ' } end end """ When I run `rake spec` Then the output should contain "4 examples, 0 failures" ammeter-1.1.4/features/generator_with_shell_prompts_spec.feature0000644000175000017500000000400413530106021026073 0ustar utkarsh2102utkarsh2102@example_app Feature: generator with shell prompts spec Generator specs live in spec/generators. In order to access the generator's methods you can call them on the "generator" object. Background: A simple generator Given a file named "lib/generators/awesome/lamest_generator.rb" with: """ class LamestGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) class_option :super, :type => :boolean, :default => false def create_lamest @lame = false @awesome = false @user_name = ask("What is your name?") if yes?("Are you the lamest?") @lame = true end if yes?("Are you awesome?") @awesome = true end template 'lamest.html.erb', File.join('public', name, "#{"super_" if options[:super]}lamest.html") end end """ And a file named "lib/generators/awesome/templates/lamest.html.erb" with: """ <%= @user_name %> <%= "is the lamest" if @lame %> and <%= "is not awesome!" if @awesome == false %> """ Scenario: A spec that runs the entire generator Given a file named "spec/generators/lamest_generator_spec.rb" with: """ require "rails_helper" require 'generators/awesome/lamest_generator' describe LamestGenerator do describe 'invoke' do before do gen = generator %w(my_dir) set_shell_prompt_responses(gen, { :ask => "Thomas", :yes? => [true, false] }) run_generator end describe 'public/my_dir/lamest.html' do subject { file('public/my_dir/lamest.html') } it { expect(subject).to exist } it { expect(subject).to contain 'Thomas is the lamest and is not awesome!' } it { expect(subject).to_not contain 'This text is not in the file' } end end end """ When I run `rake spec` Then the output should contain "3 examples, 0 failures" ammeter-1.1.4/.travis.yml0000644000175000017500000000046513530106021016012 0ustar utkarsh2102utkarsh2102language: ruby sudo: false rvm: - 2.3.0 - 2.2 - 2.1.2 - 2.0.0 - ruby-head - jruby-9.1.2.0 env: - RSPEC_VERSION=master - RSPEC_VERSION='~> 3.0' bundler_args: "--retry=3 --jobs=3" script: "bundle exec rake ci --trace" matrix: allow_failures: - rvm: ruby-head - rvm: jruby-9.1.2.0 ammeter-1.1.4/.gitignore0000644000175000017500000000013713530106021015665 0ustar utkarsh2102utkarsh2102tmp doc pkg vendor .bundle *.gem Gemfile.lock gemfiles/*.lock .rvmrc **/.DS_Store *~ *.swp .rbxammeter-1.1.4/Gemfile0000644000175000017500000000327313530106021015174 0ustar utkarsh2102utkarsh2102source "http://rubygems.org" rspec_version = ENV['RSPEC_VERSION'] rspec_major_version = (rspec_version && rspec_version != 'master') ? rspec_version.scan(/\d+/).first : '3' if rspec_version == 'master' gem "rspec-rails", :git => 'git://github.com/rspec/rspec-rails.git' gem "rspec", :git => 'git://github.com/rspec/rspec.git' gem "rspec-core", :git => 'git://github.com/rspec/rspec-core.git' gem "rspec-expectations", :git => 'git://github.com/rspec/rspec-expectations.git' gem "rspec-mocks", :git => 'git://github.com/rspec/rspec-mocks.git' gem "rspec-collection_matchers", :git => 'git://github.com/rspec/rspec-collection_matchers.git' gem "rspec-support", :git => 'git://github.com/rspec/rspec-support.git' else gem 'rspec-rails', rspec_version gem 'rspec', rspec_version end if rspec_major_version == '2' || RUBY_VERSION.to_f < 1.9 # rspec 2.x does not support Rails 4.1+ nor does Ruby 1.8.7 gem 'rails', '~> 3.2' gem 'uglifier', '~> 1.2.4' gem 'rake', '~> 0.9.2.2' gem 'coffee-rails', '~> 3.2' gem 'sass-rails', '~> 3.2' gem 'jquery-rails', '~> 2.0' gem 'haml-rails', '~> 0.4' gem 'execjs', '~> 2.0.0' elsif rspec_major_version == '3' if RUBY_VERSION < '2.2.2' gem 'rails', '< 5.0' # rails 5 is ruby >= 2.2.2 else gem 'rails', '>= 4.0' end gem 'uglifier', '>= 1.3' gem 'rake', '>= 0.10' gem 'coffee-rails', '>= 4.0' gem 'sass-rails', '>= 4.0' gem 'jquery-rails', '>= 3.0' gem 'haml-rails', '>= 0.5' else raise "rspec version #{rspec_version} is not supported" end gem "i18n", '< 0.7.0' if RUBY_VERSION < '1.9.3' gem "rack", '<= 1.6.4' if RUBY_VERSION < '2.2.2' # Specify your gem's dependencies in rspec-rails-generator-specs.gemspec gemspec ammeter-1.1.4/History.md0000644000175000017500000000304113530106021015655 0ustar utkarsh2102utkarsh2102## Ammeter release history ### 1.0.0 / 2014-04-07 [full changelog](https://github.com/alexrothenberg/ammeter/compare/v0.2.9...v1.0.0) * Compatible with RSpec 3 & RSpec 2 ### 0.2.9 / 2013-06-06 [full changelog](https://github.com/alexrothenberg/ammeter/compare/v0.2.8...v0.2.9) * Improves `contain` matcher for generated file contents * Adds `ensure_current_path` method to GeneratorExampleGroup ### 0.2.8 / 2012-07-06 [full changelog](https://github.com/alexrothenberg/ammeter/compare/v0.2.7...v0.2.8) Fixes regression with initialization for gems that create a test Rails.application (problem since 0.2.6) ### 0.2.7 / 2012-07-05 [full changelog](https://github.com/alexrothenberg/ammeter/compare/v0.2.6...v0.2.7) * Fixed issue #13 - Railtie initializer preventing devise from loading * Fixed issue #12 - Only load_generators if we Rails is available. Regression introduced in 0.2.6 ### 0.2.6 / 2012-06-28 [full changelog](https://github.com/alexrothenberg/ammeter/compare/v0.2.5...v0.2.6) * Fixed issue #11 - testing generators that depend on other generators using `hook_for` ### 0.2.5 / 2012-05-03 [full changelog](https://github.com/alexrothenberg/ammeter/compare/v0.2.4...v0.2.5) * Fixed issue #9 with for rails 4 ### 0.2.4 / 2012-04-06 [full changelog](https://github.com/alexrothenberg/ammeter/compare/v0.2.3...v0.2.4) * Fixed issue #8 with migration_file and be_a_migration [@EppO] ### 0.2.3 / 2012-03-05 [full changelog](https://github.com/alexrothenberg/ammeter/compare/v0.2.2...v0.2.3) * Fix Rails 3.2 deprecation warning [@yabawock]