ammeter-1.1.7/ 0000755 0000041 0000041 00000000000 14620142431 013177 5 ustar www-data www-data ammeter-1.1.7/ammeter.gemspec 0000644 0000041 0000041 00000003163 14620142431 016201 0 ustar www-data www-data # -*- 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.7/.gitignore 0000644 0000041 0000041 00000000137 14620142431 015170 0 ustar www-data www-data tmp
doc
pkg
vendor
.bundle
*.gem
Gemfile.lock
gemfiles/*.lock
.rvmrc
**/.DS_Store
*~
*.swp
.rbx ammeter-1.1.7/.github/ 0000755 0000041 0000041 00000000000 14620142431 014537 5 ustar www-data www-data ammeter-1.1.7/.github/workflows/ 0000755 0000041 0000041 00000000000 14620142431 016574 5 ustar www-data www-data ammeter-1.1.7/.github/workflows/ci.yml 0000644 0000041 0000041 00000003540 14620142431 017714 0 ustar www-data www-data name: Ammeter CI
on:
push:
branches:
- 'main'
pull_request:
branches:
- '*'
jobs:
test:
name: 'Ruby: ${{ matrix.ruby }}, Rspec: ${{matrix.env.RSPEC_VERSION}}, Rails: ${{ matrix.env.RAILS_VERSION }}'
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- ruby: 3.0
env:
RSPEC_VERSION: 'master'
RAILS_VERSION: '~> 6.1.0'
- ruby: 3.0
env:
RSPEC_VERSION: '~> 4.0'
RAILS_VERSION: '~> 6.1.0'
- ruby: 3.0
env:
RSPEC_VERSION: '~> 4.0'
RAILS_VERSION: '~> 6.0.0'
- ruby: 3.0
env:
RSPEC_VERSION: '~> 3.9'
RAILS_VERSION: '~> 6.0.0'
- ruby: 2.5
env:
RSPEC_VERSION: 'master'
RAILS_VERSION: '~> 6.1.0'
- ruby: 2.5
env:
RSPEC_VERSION: '~> 4.0'
RAILS_VERSION: '~> 6.1.0'
- ruby: 2.5
env:
RSPEC_VERSION: '~> 4.0'
RAILS_VERSION: '~> 6.0.0'
- ruby: 2.5
env:
RSPEC_VERSION: '~> 4.0'
RAILS_VERSION: '~> 5.2.0'
- ruby: 2.5
env:
RSPEC_VERSION: '~> 3.9'
RAILS_VERSION: '~> 6.0.0'
- ruby: 2.5
env:
RSPEC_VERSION: '~> 3.9'
RAILS_VERSION: '~> 5.2.0'
- ruby: ruby-head
env:
RSPEC_VERSION: 'master'
RAILS_VERSION: '~> 6.1.0'
env: ${{ matrix.env }}
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle install
- run: bundle exec rake ci
continue-on-error: ${{ matrix.allow_failure || false }}
ammeter-1.1.7/lib/ 0000755 0000041 0000041 00000000000 14620142431 013745 5 ustar www-data www-data ammeter-1.1.7/lib/ammeter.rb 0000644 0000041 0000041 00000000271 14620142431 015724 0 ustar www-data www-data require '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.7/lib/ammeter/ 0000755 0000041 0000041 00000000000 14620142431 015377 5 ustar www-data www-data ammeter-1.1.7/lib/ammeter/init.rb 0000644 0000041 0000041 00000000641 14620142431 016670 0 ustar www-data www-data require '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.7/lib/ammeter/version.rb 0000644 0000041 0000041 00000000047 14620142431 017412 0 ustar www-data www-data module Ammeter
VERSION = "1.1.7"
end
ammeter-1.1.7/lib/ammeter/output_capturer.rb 0000644 0000041 0000041 00000001403 14620142431 021167 0 ustar www-data www-data module 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
end ammeter-1.1.7/lib/ammeter/railtie.rb 0000644 0000041 0000041 00000000234 14620142431 017354 0 ustar www-data www-data module Ammeter
class Railtie < Rails::Railtie
initializer 'my_engine.interact_with_routes' do |app|
require 'ammeter/init.rb'
end
end
end
ammeter-1.1.7/lib/ammeter/rspec/ 0000755 0000041 0000041 00000000000 14620142431 016513 5 ustar www-data www-data ammeter-1.1.7/lib/ammeter/rspec/rspec_2_compatibility.rb 0000644 0000041 0000041 00000001041 14620142431 023322 0 ustar www-data www-data require '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
end ammeter-1.1.7/lib/ammeter/rspec/generator/ 0000755 0000041 0000041 00000000000 14620142431 020501 5 ustar www-data www-data ammeter-1.1.7/lib/ammeter/rspec/generator/example/ 0000755 0000041 0000041 00000000000 14620142431 022134 5 ustar www-data www-data ammeter-1.1.7/lib/ammeter/rspec/generator/example/generator_example_group.rb 0000644 0000041 0000041 00000006053 14620142431 027402 0 ustar www-data www-data require '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
Pathname.new(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.7/lib/ammeter/rspec/generator/example/generator_example_helpers.rb 0000644 0000041 0000041 00000002070 14620142431 027703 0 ustar www-data www-data require '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.7/lib/ammeter/rspec/generator/matchers.rb 0000644 0000041 0000041 00000000424 14620142431 022634 0 ustar www-data www-data require '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.7/lib/ammeter/rspec/generator/matchers/ 0000755 0000041 0000041 00000000000 14620142431 022307 5 ustar www-data www-data ammeter-1.1.7/lib/ammeter/rspec/generator/matchers/be_a_migration.rb 0000644 0000041 0000041 00000000612 14620142431 025572 0 ustar www-data www-data RSpec::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.7/lib/ammeter/rspec/generator/matchers/exist.rb 0000644 0000041 0000041 00000000740 14620142431 023771 0 ustar www-data www-data # DEPRECATED: use `expect(Pathname.new(path)).to exist` instead
RSpec::Matchers.define :exist do |*expected|
match do |file_path|
if !(file_path.respond_to?(:exist?) || file_path.respond_to?(:exists?))
ActiveSupport::Deprecation.warn "The `exist` matcher overrides one built-in by RSpec; use `expect(Pathname.new(path)).to exist` instead"
File.exist?(file_path)
else
RSpec::Matchers::BuiltIn::Exist.new(*expected).matches?(file_path)
end
end
end
ammeter-1.1.7/lib/ammeter/rspec/generator/matchers/have_correct_syntax.rb 0000644 0000041 0000041 00000002351 14620142431 026707 0 ustar www-data www-data RSpec::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
if Rails::VERSION::STRING < "6.0"
view = ActionView::Template::Handlers::ERB.call(OpenStruct.new(:source => code))
else
view = ActionView::Template::Handlers::ERB.call(OpenStruct.new, code)
end
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.7/lib/ammeter/rspec/generator/matchers/have_method.rb 0000644 0000041 0000041 00000000472 14620142431 025122 0 ustar www-data www-data RSpec::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.7/lib/ammeter/rspec/generator/matchers/contain.rb 0000644 0000041 0000041 00000002773 14620142431 024300 0 ustar www-data www-data RSpec::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.7/lib/ammeter/rspec/generator/example.rb 0000644 0000041 0000041 00000001760 14620142431 022465 0 ustar www-data www-data require '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
c.include Ammeter::RSpec::Rails::GeneratorExampleGroup,
: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.7/LICENSE.txt 0000644 0000041 0000041 00000002042 14620142431 015020 0 ustar www-data www-data Copyright (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.7/spec/ 0000755 0000041 0000041 00000000000 14620142431 014131 5 ustar www-data www-data ammeter-1.1.7/spec/spec_helper.rb 0000644 0000041 0000041 00000001127 14620142431 016750 0 ustar www-data www-data require '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.7/spec/ammeter/ 0000755 0000041 0000041 00000000000 14620142431 015563 5 ustar www-data www-data ammeter-1.1.7/spec/ammeter/rspec/ 0000755 0000041 0000041 00000000000 14620142431 016677 5 ustar www-data www-data ammeter-1.1.7/spec/ammeter/rspec/generator/ 0000755 0000041 0000041 00000000000 14620142431 020665 5 ustar www-data www-data ammeter-1.1.7/spec/ammeter/rspec/generator/example/ 0000755 0000041 0000041 00000000000 14620142431 022320 5 ustar www-data www-data ammeter-1.1.7/spec/ammeter/rspec/generator/example/generator_example_group_spec.rb 0000644 0000041 0000041 00000005030 14620142431 030572 0 ustar www-data www-data require "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_path).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.7/spec/ammeter/rspec/generator/example/generator_example_helpers_spec.rb 0000644 0000041 0000041 00000002007 14620142431 031101 0 ustar www-data www-data require "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.7/spec/ammeter/rspec/generator/matchers/ 0000755 0000041 0000041 00000000000 14620142431 022473 5 ustar www-data www-data ammeter-1.1.7/spec/ammeter/rspec/generator/matchers/have_method_spec.rb 0000644 0000041 0000041 00000001061 14620142431 026313 0 ustar www-data www-data require '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.7/spec/ammeter/rspec/generator/matchers/exist_spec.rb 0000644 0000041 0000041 00000001221 14620142431 025162 0 ustar www-data www-data require '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
it 'maintains default RSpec behavior', :aggregate_failures do
path = Pathname.new('/some/file/path')
allow(path).to receive(:exist?).and_return(true)
expect(path).to exist
allow(path).to receive(:exist?).and_return(false)
expect(path).not_to exist
end
end
ammeter-1.1.7/spec/ammeter/rspec/generator/matchers/contain_spec.rb 0000644 0000041 0000041 00000001743 14620142431 025472 0 ustar www-data www-data require '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.7/spec/ammeter/rspec/generator/matchers/be_a_migration_spec.rb 0000644 0000041 0000041 00000001643 14620142431 026775 0 ustar www-data www-data require '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.7/spec/ammeter/rspec/generator/matchers/have_correct_syntax_spec.rb 0000644 0000041 0000041 00000005365 14620142431 030115 0 ustar www-data www-data require '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 %>
<%= element.id %> | <%= element.title %> | <%= link_to 'Show', element_path(element) %> |
This test should fail because I didn't close an each loop.
<% @elements.each do |element| %>