source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | nathankot/webstub | https://github.com/nathankot/webstub | Rakefile | Ruby | mit | 88 | master | 883 | $:.unshift("/Library/RubyMotion/lib")
begin
if ENV['osx']
require 'motion/project/template/osx'
else
require 'motion/project/template/ios'
end
rescue LoadError
require 'motion/project'
end
require 'bundler/setup'
Bundler.setup
Bundler.require
require 'rubygems/tasks'
Gem::Tasks.new
Motion::Project... |
github | nathankot/webstub | https://github.com/nathankot/webstub | webstub.gemspec | Ruby | mit | 88 | master | 760 | # -*- encoding: utf-8 -*-
require File.join(File.dirname(__FILE__), "lib/webstub/version")
Gem::Specification.new do |gem|
gem.authors = ["Matt Green"]
gem.email = ["mattgreenrocks@gmail.com"]
gem.description = "Easily stub out HTTP responses in RubyMotion specs"
gem.summary = "Easily stu... |
github | nathankot/webstub | https://github.com/nathankot/webstub | Guardfile | Ruby | mit | 88 | master | 256 | # A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'motion', :env => {:output => 'test_unit'}, :keep_failed => false do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/[^/]+/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
end |
github | nathankot/webstub | https://github.com/nathankot/webstub | lib/webstub.rb | Ruby | mit | 88 | master | 240 | gem_name = File.basename(__FILE__).gsub(/\.rb$/, "")
Motion::Project::App.setup do |app|
app.development do
gem_files = Dir.glob(File.join(File.dirname(__FILE__), gem_name, "**/*.rb"))
app.files = gem_files + app.files
end
end |
github | nathankot/webstub | https://github.com/nathankot/webstub | lib/webstub/stub.rb | Ruby | mit | 88 | master | 4,298 | module WebStub
class Stub
METHODS = ["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "PATCH"].freeze
def initialize(method, url)
@request_method = canonicalize_method(method)
raise ArgumentError, "invalid method name" unless METHODS.include? @request_method
@requests = 0
@request... |
github | nathankot/webstub | https://github.com/nathankot/webstub | lib/webstub/protocol.rb | Ruby | mit | 88 | master | 4,371 | module WebStub
class Protocol < NSURLProtocol
def self.add_stub(*args)
registry.add_stub(*args)
end
def self.canInitWithRequest(request)
return false unless spec_mode?
return false unless supported?(request)
if stub_for(request)
return true
end
! network_acce... |
github | nathankot/webstub | https://github.com/nathankot/webstub | lib/webstub/json.rb | Ruby | mit | 88 | master | 555 | module WebStub
module JSON
def self.generate(hash)
error = Pointer.new(:object)
result = NSJSONSerialization.dataWithJSONObject(hash, options:0, error:error)
NSString.alloc.initWithData(result, encoding:NSUTF8StringEncoding)
end
def self.parse(str)
data = str
unless data.is... |
github | nathankot/webstub | https://github.com/nathankot/webstub | lib/webstub/uri.rb | Ruby | mit | 88 | master | 867 | module WebStub
module URI
def self.decode_www_form(str)
str.split("&").inject({}) do |hash, component|
key, value = component.split("=", 2)
hash[decode_www_form_component(key)] = decode_www_form_component(value)
hash
end
end
def self.decode_www_form_component(str)
... |
github | nathankot/webstub | https://github.com/nathankot/webstub | lib/webstub/registry.rb | Ruby | mit | 88 | master | 469 | module WebStub
class Registry
def initialize()
@stubs = []
end
def add_stub(method, path)
stub = Stub.new(method, path)
@stubs << stub
stub
end
def reset
@stubs = []
end
def size
@stubs.size
end
def stub_matching(method, url, options={})... |
github | nathankot/webstub | https://github.com/nathankot/webstub | lib/webstub/api.rb | Ruby | mit | 88 | master | 476 | module WebStub
module API
extend self
def disable_network_access!
protocol.disable_network_access!
end
def enable_network_access!
protocol.enable_network_access!
end
def stub_request(method, path)
protocol.add_stub(method, path)
end
def reset_stubs
protocol.... |
github | nathankot/webstub | https://github.com/nathankot/webstub | lib/webstub/patch/session_configuration.rb | Ruby | mit | 88 | master | 1,020 | if Kernel.const_defined?(:NSURLSessionConfiguration)
class NSURLSessionConfiguration
class << self
alias_method :originalDefaultSessionConfiguration, :defaultSessionConfiguration
def defaultSessionConfiguration
config = originalDefaultSessionConfiguration
protocols = (config.protocol... |
github | nathankot/webstub | https://github.com/nathankot/webstub | spec/protocol_spec.rb | Ruby | mit | 88 | master | 2,401 | describe WebStub::Protocol do
before do
WebStub::Protocol.reset_stubs
@request = NSURLRequest.requestWithURL(NSURL.URLWithString("http://www.google.com/"))
end
describe ".canInitWithRequest" do
describe "when network access is allowed" do
it "returns false for unstubbed requests" do
We... |
github | nathankot/webstub | https://github.com/nathankot/webstub | spec/spec_helpers_spec.rb | Ruby | mit | 88 | master | 273 | describe WebStub::SpecHelpers do
extend WebStub::SpecHelpers
it "includes WebStub::API" do
self.class.ancestors.should.include? WebStub::API
end
it "calls reset_stubs in an after block" do
self.instance_variable_get(:@after).should.not.be.empty
end
end |
github | nathankot/webstub | https://github.com/nathankot/webstub | spec/stub_spec.rb | Ruby | mit | 88 | master | 8,361 | describe WebStub::Stub do
before do
@stub = WebStub::Stub.new(:get, "http://www.yahoo.com/")
end
it "holds the method and the path" do
@stub.should.not.be.nil
end
it "allows all valid HTTP methods" do
WebStub::Stub::METHODS.each do |method|
lambda { WebStub::Stub.new(method, "http://www.ya... |
github | nathankot/webstub | https://github.com/nathankot/webstub | spec/json_spec.rb | Ruby | mit | 88 | master | 1,394 | describe WebStub::JSON do
describe ".generate" do
it "encodes an empty Array as JSON" do
WebStub::JSON.generate([]).should == "[]"
end
it 'encodes an empty Hash as JSON' do
WebStub::JSON.generate({}).should == "{}"
end
it 'encodes a Hash as JSON' do
WebStub::JSON.generate({
... |
github | nathankot/webstub | https://github.com/nathankot/webstub | spec/uri_spec.rb | Ruby | mit | 88 | master | 1,145 | describe WebStub::URI do
describe ".decode_www_form" do
it "decodes a simple form into a Hash" do
WebStub::URI.decode_www_form("a=42&b=hello").should == { "a" => "42", "b" => "hello" }
end
it "unescapes reserved characters properly" do
WebStub::URI.decode_www_form("comment=hello%2C+my+name+is... |
github | nathankot/webstub | https://github.com/nathankot/webstub | spec/registry_spec.rb | Ruby | mit | 88 | master | 516 | describe WebStub::Registry do
before do
@registry = WebStub::Registry.new()
end
it "has no requests initially" do
@registry.size.should == 0
end
describe "#add_stub" do
it "inserts a stub" do
@registry.add_stub(:get, "http://www.yahoo.com/")
@registry.size.should == 1
end
end
... |
github | nathankot/webstub | https://github.com/nathankot/webstub | spec/api_spec.rb | Ruby | mit | 88 | master | 7,003 | describe WebStub::API do
before do
WebStub::API.reset_stubs
@url = "http://www.example.com/"
@request = NSURLRequest.requestWithURL(NSURL.URLWithString(@url))
end
describe ".stub_request" do
it "returns the newly added stub" do
WebStub::API.stub_request(:get, @url).should.not.be.nil
en... |
github | nathankot/webstub | https://github.com/nathankot/webstub | spec/helpers/request_helper.rb | Ruby | mit | 88 | master | 2,446 | class Response
def initialize(body, response, error, resp_type)
allocators = {:string_resp => ->(b) { alloc_data_string(b) },
:binary_resp => ->(b) { alloc_data_binary(b) }}
@body = allocators[resp_type].call(body)
@headers = response ? response.allHeaderFields : nil
@error = error... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | mysql2xxxx.gemspec | Ruby | mit | 88 | master | 1,027 | # -*- encoding: utf-8 -*-
require File.expand_path("../lib/mysql2xxxx/version", __FILE__)
Gem::Specification.new do |s|
s.name = "mysql2xxxx"
s.version = Mysql2xxxx::VERSION
s.authors = ["Seamus Abshere"]
s.email = ["seamus@abshere.net"]
s.homepage = "https://github.com/seamusabshere/... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | Gemfile | Ruby | mit | 88 | master | 215 | source "http://rubygems.org"
gemspec
gem 'rake'
gem 'activerecord'
gem 'posix-spawn'
if RUBY_VERSION >= '1.9'
gem 'ruby-debug19'
else
if RUBY_PLATFORM != 'java'
gem 'memprof'
end
gem 'ruby-debug'
end |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | Rakefile | Ruby | mit | 88 | master | 591 | require 'bundler'
Bundler::GemHelper.install_tasks
require 'bundler/setup'
require 'rake'
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
task :default => :test
begin
require 'rake/rdoctask'
Rake::RDocTask.n... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | benchmark/target.rb | Ruby | mit | 88 | master | 674 | #!/usr/bin/env ruby
unless RUBY_VERSION >= '1.9'
require 'rubygems'
require 'memprof'
end
$LOAD_PATH.unshift File.join(ENV['HERE'], '..', 'lib')
require 'mysql2xxxx'
format = ARGV[0]
if RUBY_VERSION >= '1.9'
# unfortunately can't use memprof
a = Mysql2xxxx.const_get(format).new :user => ENV['DBUSER'], :passwo... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | benchmark/benchmark.rb | Ruby | mit | 88 | master | 2,163 | #!/usr/bin/env ruby
ENV['HERE'] = File.dirname(__FILE__)
ENV['DBUSER'] = 'root'
ENV['DBPASSWORD'] = 'password'
ENV['DBNAME'] = 'mysql2xxxx_benchmark'
ENV['MEMPROF_REPORT_PATH'] = File.expand_path('memprof.txt')
ENV['DUMP_PATH'] = File.expand_path('a.dump')
ENV['EXECUTE'] = 'SELECT * FROM five_thousand_rows'
FORMATS = ... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | test/test_active_record_config_stealing.rb | Ruby | mit | 88 | master | 448 | require 'helper'
# just to be able to steal the config
ActiveRecord::Base.establish_connection(
'adapter' => 'mysql2',
'database' => TEST_DB,
'username' => MYSQL_USER,
'password' => MYSQL_PASS
)
class TestActiveRecordConfigStealing < Test::Unit::TestCase
def test_steals_config
a = Mysql2xxxx::JSON.new @... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | test/test_cli.rb | Ruby | mit | 88 | master | 892 | require 'helper'
class TestCli < Test::Unit::TestCase
def test_xml
a = POSIX::Spawn::Child.new %{mysql2xml --user=#{@options[:user]} --password=#{@options[:password]} --database=#{@options[:database]} --execute="#{@options[:execute]}"}
assert a.out.include?('Acura')
assert !a.out.include?('DaimlerChrysle... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | test/helper.rb | Ruby | mit | 88 | master | 1,125 | require 'rubygems'
require 'bundler'
Bundler.setup
if ::Bundler.definition.specs['debugger'].first
require 'debugger'
elsif ::Bundler.definition.specs['ruby-debug'].first
require 'ruby-debug'
end
require 'test/unit'
require 'fileutils'
require 'active_record'
require 'posix/spawn'
require 'mysql2xxxx'
MYSQL_USER... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | test/test_multiline_sql.rb | Ruby | mit | 88 | master | 716 | require 'helper'
class TestMultilineSql < Test::Unit::TestCase
def test_multiline_sql
a = Mysql2xxxx::JSON.new @options.merge(:execute => %{
DROP TABLE IF EXISTS t1; CREATE TEMPORARY TABLE t1 SELECT CONCAT_WS('-', year, make_name) AS crazy_name FROM automobile_make_years; SELECT * FROM t1
})
str ... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | test/test_well_formedness.rb | Ruby | mit | 88 | master | 1,186 | require 'helper'
if RUBY_VERSION >= '1.9'
require 'csv'
else
require 'fastercsv'
end
class TestWellFormedness < Test::Unit::TestCase
def test_xml
a = POSIX::Spawn::Child.new %{./bin/mysql2xml --user=#{@options[:user]} --password=#{@options[:password]} --database=#{@options[:database]} --execute="#{@options[... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | test/test_extra_outputs.rb | Ruby | mit | 88 | master | 1,156 | require 'helper'
class TestExtraOutputs < Test::Unit::TestCase
def test_mysql2json_to_s
a = Mysql2xxxx::JSON.new @options
str = a.to_s
assert str.include?('Acura')
assert !str.include?('DaimlerChrysler')
end
def test_mysql2json_to_path
path = '/tmp/test_mysql2json_to_path'
a = Mysq... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | test/test_mysql2xxxx.rb | Ruby | mit | 88 | master | 976 | # coding: utf-8
require 'helper'
class TestMysql2xxxx < Test::Unit::TestCase
def test_1_mysql2json
a = Mysql2xxxx::JSON.new @options
str = a.to_s
assert str.include?('Acura')
if RUBY_VERSION >= '1.9'
assert str.include?('Citro\u00ebn')
else
assert str.include?('Citroën')
end
a... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | lib/mysql2xxxx.rb | Ruby | mit | 88 | master | 375 | unless RUBY_VERSION >= '1.9'
$KCODE = 'U'
end
require 'active_support'
require 'active_support/version'
require 'active_support/core_ext' if ::ActiveSupport::VERSION::MAJOR >= 3
require 'mysql2'
require 'mysql2xxxx/config'
require 'mysql2xxxx/writer'
require 'mysql2xxxx/writer/json'
require 'mysql2xxxx/writer/csv'
... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | lib/mysql2xxxx/config.rb | Ruby | mit | 88 | master | 1,465 | module Mysql2xxxx
class Config
attr_reader :user_specified_options
def initialize(user_specified_options = {})
@user_specified_options = user_specified_options.symbolize_keys
end
def user
user_specified_options[:user] || active_record_config.try(:[], :username)
end
def pa... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | lib/mysql2xxxx/writer.rb | Ruby | mit | 88 | master | 1,190 | require 'stringio'
module Mysql2xxxx
class Writer
attr_reader :config
def initialize(options = {})
@config = Config.new options
end
def last_statement
return @last_statement if @last_statement.is_a? ::String
statements = config.execute.split(';').select { |statement| state... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | lib/mysql2xxxx/cli.rb | Ruby | mit | 88 | master | 643 | require 'mixlib/cli'
module Mysql2xxxx
class Cli
include ::Mixlib::CLI
%w{ user password host Port database }.each do |o|
option o.downcase.to_sym,
:short => "-#{o[0,1]} #{o.upcase}",
:long => "--#{o.downcase}=#{o.upcase}",
:description => "Set MySQL #{o.downcase}"
end
... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | lib/mysql2xxxx/writer/xml.rb | Ruby | mit | 88 | master | 961 | module Mysql2xxxx
class XML < Writer
# sabshere 2/10/11 dkastner pointed out that this doesn't include metadata like later versions of mysql do
# this matches the xml generated by "mysql --xml"
# i tried to use builder, but the String#to_xs nonsense got in the way
def to_file(f)
result = client.... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | lib/mysql2xxxx/writer/json.rb | Ruby | mit | 88 | master | 413 | require 'multi_json'
module Mysql2xxxx
class JSON < Writer
def to_file(f)
first = true
f.write '['
client.query(last_statement, :stream => true, :cache_rows => false).each do |hsh|
next if hsh.nil?
if first
first = false
else
f.write ','
end
... |
github | seamusabshere/mysql2xxxx | https://github.com/seamusabshere/mysql2xxxx | lib/mysql2xxxx/writer/csv.rb | Ruby | mit | 88 | master | 681 | if RUBY_VERSION >= '1.9'
require 'csv'
else
require 'fastercsv'
end
module Mysql2xxxx
class CSV < Writer
SLASH_N = '\N'.freeze
def to_file(f)
slash_n = config.slash_n
result = client.query(last_statement, :stream => true, :cache_rows => false, :as => :array)
fields = result.fields
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | Rakefile | Ruby | mit | 88 | main | 841 | # frozen_string_literal: true
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'spellr/rake_task'
require_relative 'lib/leftovers/rake_task'
::RuboCop::RakeTask.new
::RSpec::Core::RakeTask.new(:spec)
::Spellr::RakeTask.generate_task
::Leftovers::Ra... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | leftovers.gemspec | Ruby | mit | 88 | main | 2,078 | # frozen_string_literal: true
lib = ::File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'leftovers/version'
::Gem::Specification.new do |spec|
spec.name = 'leftovers'
spec.version = ::Leftovers::VERSION
spec.authors = ['Dana Sherson']
spec.email = ['robot@dana.sh... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | bin/test_autoload.rb | Ruby | mit | 88 | main | 1,429 | #!/usr/bin/env ruby
# frozen_string_literal: true
@count = 0
module AutoloadRegistry
def autoload(name, path)
::AutoloadRegistry[self] << name
super
end
def self.[](klass)
@autoload_registry ||= {}
@autoload_registry[klass] ||= []
end
end
::Module.prepend ::AutoloadRegistry
def print_overw... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/definition_set_spec.rb | Ruby | mit | 88 | main | 255 | # frozen_string_literal: true
require 'spec_helper'
::RSpec.describe ::Leftovers::DefinitionSet do
describe 'to_s' do
it 'has multiple names' do
ds = described_class.new(%w{one two})
expect(ds.to_s).to eq 'one, two'
end
end
end |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/leftovers_spec.rb | Ruby | mit | 88 | main | 817 | # frozen_string_literal: true
::RSpec.describe ::Leftovers do
describe 'version' do
changelog = ::File.read(::File.expand_path('../CHANGELOG.md', __dir__))
changelog_version = changelog.match(/^# v([\d.]+)$/)&.captures&.first
it "has the version number: #{changelog_version}, matching the changelog" do
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/node_spec.rb | Ruby | mit | 88 | main | 9,098 | # frozen_string_literal: true
RSpec.describe ::Leftovers::AST::Node do
let(:send_node) { ::Leftovers::Parser.parse_with_comments('foo()').first }
let(:send_then_send_node) { ::Leftovers::Parser.parse_with_comments('foo().bar()').first }
let(:const_then_send_node) { ::Leftovers::Parser.parse_with_comments('Foo.ba... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/config_documentation_spec.rb | Ruby | mit | 88 | main | 805 | # frozen_string_literal: true
require 'fast_ignore'
::RSpec.describe ::Leftovers::Config do
config_methods = described_class.new(:rails).public_methods - ::Class.new.new.public_methods
describe 'config in documentation' do
files = ::FastIgnore.new(include_rules: ['*.md', '!CHANGELOG.md', '!vendor'])
file... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/config_fuzz_spec.rb | Ruby | mit | 88 | main | 779 | # frozen_string_literal: true
require 'support/config_fuzzer'
::RSpec.describe ::Leftovers::Config do
next if ::ENV['COVERAGE']
config_methods = described_class.new(:rails).public_methods - ::Class.new.new.public_methods
describe 'fuzzed config' do
::ENV.fetch('FUZZ_ITERATIONS', 10).to_i.times do |n|
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/cli_spec.rb | Ruby | mit | 88 | main | 18,249 | # frozen_string_literal: true
require 'parallel'
::RSpec.describe ::Leftovers::CLI, type: :cli do
describe 'leftovers', :with_temp_dir do
before do
allow(::Leftovers).to receive(:try_require_cache).and_call_original
allow(::Leftovers).to receive(:try_require_cache).with('bundler').and_return(false)
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/config_spec.rb | Ruby | mit | 88 | main | 22,275 | # frozen_string_literal: true
require 'did_you_mean' # force 2.5 and 2.6 to have suggestions.
::RSpec.describe ::Leftovers::Config do
describe '.dynamic' do
it 'can report config parse errors' do
config = described_class.new('invalid', content: <<~YML)
dynamic:
- name: my_method
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/config_built_in_spec.rb | Ruby | mit | 88 | main | 1,428 | # frozen_string_literal: true
::RSpec.describe ::Leftovers::Config do
config_methods = described_class.new(:rails).public_methods - ::Class.new.new.public_methods
describe 'built in config' do
files = ::Pathname.glob("#{__dir__}/../lib/config/*.yml")
gems = files.map { |f| f.basename.sub_ext('').to_s }
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/precompiler_error_spec.rb | Ruby | mit | 88 | main | 2,410 | # frozen_string_literal: true
::RSpec.describe ::Leftovers::PrecompileError do
describe '#warn' do
it 'can include a line and column' do
error = described_class.new('the message', line: 1, column: 5)
expect { error.warn(path: 'whatever.jpg') }.to print_warning(<<~MESSAGE)
Leftovers::Precompil... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/config_loader_spec.rb | Ruby | mit | 88 | main | 5,791 | # frozen_string_literal: true
require 'did_you_mean' # force 2.5 and 2.6 to have suggestions.
::RSpec.describe ::Leftovers::ConfigLoader do
let(:name) { 'foo' }
let(:path) { "#{name}.yml" }
describe '#load' do
subject { described_class.load(name, path: path, content: yaml) }
context 'with a empty hash... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/spec_helper.rb | Ruby | mit | 88 | main | 5,334 | # frozen_string_literal: true
require 'fileutils'
::FileUtils.rm_rf(::File.join(__dir__, '..', 'coverage'))
require 'bundler/setup'
require 'simplecov' if ::ENV['COVERAGE'] == '1'
require_relative '../lib/leftovers'
require 'timecop'
require 'tty_string'
::RSpec.configure do |config|
# Enable flags like --only-fa... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/merged_config_spec.rb | Ruby | mit | 88 | main | 3,443 | # frozen_string_literal: true
::RSpec.describe ::Leftovers::MergedConfig do
describe '<<' do
it 'handles clearing memoization' do
subject << :ruby
original_exclude_paths = subject.exclude_paths
original_include_paths = subject.include_paths
original_test_paths = subject.test_paths
o... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/runner_spec.rb | Ruby | mit | 88 | main | 5,499 | # frozen_string_literal: true
::RSpec.describe ::Leftovers::Runner do
describe '.leftovers', :with_temp_dir do
subject { described_class.new.collection }
it "doesn't care about using one of multiple simultaneous defined methods" do
temp_file '.leftovers.yml', <<~YML
dynamic:
name: at... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/matcher_builders/string_pattern_spec.rb | Ruby | mit | 88 | main | 2,284 | # frozen_string_literal: true
::RSpec.describe ::Leftovers::MatcherBuilders::StringPattern do
describe '.build' do
it 'returns nil when given nothing' do
expect(described_class.build).to be_nil
end
it 'returns an anchored regex when given match' do
expect(described_class.build(match: 'a')).t... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/support/temp_file_helper.rb | Ruby | mit | 88 | main | 816 | # frozen_string_literal: true
require 'tmpdir'
require 'pathname'
module TempFileHelper
def temp_file(filename, body = '')
raise 'Add :with_temp_dir to the metadata' unless @__temp_dir
path = @__temp_dir.join(filename)
path.parent.mkpath
path.write(body)
path
end
def temp_dir
@__temp_d... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/support/expects_output_helper.rb | Ruby | mit | 88 | main | 379 | # frozen_string_literal: true
module ExpectsOutput
def expects_output!
@expects_output = true
end
end
::RSpec.configure do |c|
c.include ExpectsOutput
c.before { ::Leftovers.reset }
c.after do
next if defined?(@expects_output) && @expects_output
expect(::Leftovers.stderr.string).to be_empty
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/support/config_fuzzer.rb | Ruby | mit | 88 | main | 4,257 | # frozen_string_literal: true
require 'yaml'
module Leftovers
class ConfigLoader
class Fuzzer # rubocop:disable Metrics/ClassLength
def initialize(iteration)
srand ::RSpec.configuration.seed + iteration
end
def to_yaml
fuzz_object(DocumentSchema).to_yaml
end
priva... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/support/ruby_version_helper.rb | Ruby | mit | 88 | main | 329 | # frozen_string_literal: true
::RSpec.configure do |c|
c.before do |example|
ruby_version = example.metadata[:ruby_version_at_least]
next unless ruby_version
if Gem::Version.new(ruby_version) > Gem::Version.new(RUBY_VERSION)
skip "Only run this example in ruby version >= #{ruby_version}"
end
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/support/cli_helper.rb | Ruby | mit | 88 | main | 226 | # frozen_string_literal: true
require 'shellwords'
module CLIHelper
def run(argv = '')
::Leftovers::CLI.new(argv: ::Shellwords.split(argv)).run
end
end
::RSpec.configure do |c|
c.include CLIHelper, type: :cli
end |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/file_collector/json_spec.rb | Ruby | mit | 88 | main | 807 | # frozen_string_literal: true
require 'spec_helper'
::RSpec.describe ::Leftovers::Precompilers::JSON do
subject(:collector) do
collector = ::Leftovers::FileCollector.new(ruby, file)
collector.collect
collector
end
let(:path) { 'foo.json' }
let(:file) do
::Leftovers::File.new(::Leftovers.pwd +... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/file_collector/erb_spec.rb | Ruby | mit | 88 | main | 1,786 | # frozen_string_literal: true
require 'spec_helper'
::RSpec.describe ::Leftovers::FileCollector do
subject(:collector) do
collector = described_class.new(ruby, file)
collector.collect
collector
end
let(:path) { 'foo.erb' }
let(:file) do
::Leftovers::File.new(::Leftovers.pwd + path)
.tap... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/file_collector/literal_spec.rb | Ruby | mit | 88 | main | 9,772 | # frozen_string_literal: true
require 'spec_helper'
::RSpec.describe ::Leftovers::FileCollector do
subject(:collector) do
collector = described_class.new(ruby, file)
collector.collect
collector
end
let(:path) { 'foo.rb' }
let(:file) { ::Leftovers::File.new(::Leftovers.pwd + path) }
let(:ruby) {... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/file_collector/inline_comments_spec.rb | Ruby | mit | 88 | main | 3,099 | # frozen_string_literal: true
require 'spec_helper'
::RSpec.describe ::Leftovers::FileCollector do
subject(:collector) do
collector = described_class.new(ruby, file)
collector.collect
collector
end
let(:path) { 'foo.rb' }
let(:file) { ::Leftovers::File.new(::Leftovers.pwd + path) }
let(:ruby) {... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/file_collector/slim_spec.rb | Ruby | mit | 88 | main | 3,002 | # frozen_string_literal: true
require 'spec_helper'
::RSpec.describe ::Leftovers::FileCollector do
subject(:collector) do
collector = described_class.new(ruby, file)
collector.collect
collector
end
let(:path) { 'foo.slim' }
let(:file) do
::Leftovers::File.new(::Leftovers.pwd + path)
.ta... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/file_collector/yaml_spec.rb | Ruby | mit | 88 | main | 1,596 | # frozen_string_literal: true
require 'spec_helper'
::RSpec.describe ::Leftovers::Precompilers::YAML do
subject(:collector) do
collector = ::Leftovers::FileCollector.new(ruby, file)
collector.collect
collector
end
let(:path) { 'foo.yaml' }
let(:file) do
::Leftovers::File.new(::Leftovers.pwd +... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/file_collector/haml_spec.rb | Ruby | mit | 88 | main | 3,263 | # frozen_string_literal: true
require 'spec_helper'
::RSpec.describe ::Leftovers::FileCollector do
subject(:collector) do
collector = described_class.new(ruby, file)
collector.collect
collector
end
let(:path) { 'foo.haml' }
let(:file) do
::Leftovers::File.new(::Leftovers.pwd + path)
.ta... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/file_collector/custom_config_spec.rb | Ruby | mit | 88 | main | 73,753 | # frozen_string_literal: true
require 'spec_helper'
::RSpec.describe ::Leftovers::FileCollector do
subject(:collector) do
collector = described_class.new(ruby, file)
collector.collect
collector
end
before do
allow(::Leftovers).to receive(:try_require_cache).and_call_original
allow(::Leftove... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/config_loader/suggester_spec.rb | Ruby | mit | 88 | main | 462 | # frozen_string_literal: true
require 'did_you_mean'
::RSpec.describe ::Leftovers::ConfigLoader::Suggester do
subject { described_class.new(%w{cat bar dog}) }
describe '#suggest' do
it 'returns spelling suggestions' do
expect(subject.suggest('car')).to eq %w{cat bar}
end
it "returns all option... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/config/ruby_spec.rb | Ruby | mit | 88 | main | 8,341 | # frozen_string_literal: true
require 'spec_helper'
::RSpec.describe 'ruby and stdlib' do
subject(:collector) do
collector = ::Leftovers::FileCollector.new(ruby, file)
collector.collect
collector
end
let(:path) { 'foo.rb' }
let(:file) { ::Leftovers::File.new(::Leftovers.pwd + path) }
let(:ruby)... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/config/rails_spec.rb | Ruby | mit | 88 | main | 15,258 | # frozen_string_literal: true
require 'spec_helper'
::RSpec.describe 'rails gem' do
subject(:collector) do
collector = ::Leftovers::FileCollector.new(ruby, file)
collector.collect
collector
end
before do
::Leftovers.config << :rails
end
let(:path) { 'foo.rb' }
let(:file) { ::Leftovers::F... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/config/rspec_spec.rb | Ruby | mit | 88 | main | 2,215 | # frozen_string_literal: true
require 'spec_helper'
::RSpec.describe 'rspec gem' do
subject(:collector) do
collector = ::Leftovers::FileCollector.new(ruby, file)
collector.collect
collector
end
before do
::Leftovers.config << :rspec
end
let(:path) { 'spec/file_spec.rb' }
let(:file) { ::L... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | spec/config/audited_spec.rb | Ruby | mit | 88 | main | 1,312 | # frozen_string_literal: true
require 'spec_helper'
::RSpec.describe 'audited gem' do
subject(:collector) do
collector = ::Leftovers::FileCollector.new(ruby, file)
collector.collect
collector
end
before do
::Leftovers.config << :audited
end
let(:path) { 'foo.rb' }
let(:file) { ::Leftover... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers.rb | Ruby | mit | 88 | main | 2,092 | # frozen_string_literal: true
module Leftovers
class Exit < ::StandardError
attr_reader :status
def initialize(status) # rubocop:disable Lint/MissingSuper
@status = status
end
end
require_relative 'leftovers/autoloader'
include Autoloader
MEMOIZED_IVARS = %i{
@config
@try_require... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/config.rb | Ruby | mit | 88 | main | 1,350 | # frozen_string_literal: true
module Leftovers
class Config
attr_reader :name
alias_method :to_sym, :name
def self.[](name_or_config)
return name_or_config if name_or_config.is_a?(self)
@loaded_configs ||= {}
@loaded_configs[name_or_config] ||= new(name_or_config)
end
def sel... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/autoloader.rb | Ruby | mit | 88 | main | 843 | # frozen_string_literal: true
module Leftovers
# zero dependency zeitwerk
module Autoloader
ALL_CAPS_NAMES = %w{ast cli version erb json yaml}.freeze
def self.included(klass)
::Dir[glob_children(klass)].each_entry do |path|
klass.autoload(class_from_path(path), path)
end
end
d... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/file.rb | Ruby | mit | 88 | main | 636 | # frozen_string_literal: true
require 'pathname'
module Leftovers
class File < ::Pathname
def relative_path
@relative_path ||= begin
relative_path_from(::Leftovers.pwd)
rescue ::ArgumentError
self
end
end
def test?
return @test if defined?(@test)
@test = :... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/definition_set.rb | Ruby | mit | 88 | main | 750 | # frozen_string_literal: true
module Leftovers
class DefinitionSet
attr_reader :definitions
def initialize(definitions)
@definitions = definitions
freeze
end
def names
@definitions.map(&:names)
end
def to_s
@definitions.map(&:to_s).join(', ')
end
def locat... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/collector.rb | Ruby | mit | 88 | main | 1,363 | # frozen_string_literal: true
require 'parallel'
require 'parser'
require 'parser/current' # to get the error message early and once before we parallel things
module Leftovers
class Collector
attr_writer :progress, :parallel
attr_reader :collection
def initialize
@count = 0
@count_calls = ... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/definition.rb | Ruby | mit | 88 | main | 1,239 | # frozen_string_literal: true
module Leftovers
class Definition
attr_reader :name, :test, :location_s, :source_line
alias_method :names, :name
alias_method :test?, :test
def initialize(
name,
location: method_node.loc.expression,
test: method_node.test_line? || ::Leftovers.config.... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/definition_node_set.rb | Ruby | mit | 88 | main | 373 | # frozen_string_literal: true
module Leftovers
class DefinitionNodeSet
attr_reader :definitions
def initialize
@definitions = []
end
def add_definition_node(definition_node)
@definitions << definition_node
end
def add_definition_set(definition_node_set)
@definitions.conca... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/reporter.rb | Ruby | mit | 88 | main | 1,284 | # frozen_string_literal: true
module Leftovers
module Reporter
class << self
def prepare; end
def report(collection)
report_list('Only directly called in tests:', collection.with_tests)
report_list('Not directly called at all:', collection.without_tests)
report_instructions
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/rake_task.rb | Ruby | mit | 88 | main | 1,227 | # frozen_string_literal: true
require 'rake'
require 'shellwords'
require_relative '../leftovers'
module Leftovers
class RakeTask
include ::Rake::DSL
def self.generate_task(name = :leftovers, *default_argv)
new(name, default_argv)
name
end
def initialize(name, default_argv)
@nam... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/file_collector.rb | Ruby | mit | 88 | main | 3,869 | # frozen_string_literal: true
require 'set'
module Leftovers
class FileCollector
class Error < ::Leftovers::Error; end
include Autoloader
attr_reader :calls, :allow_lines, :test_lines, :dynamic_lines
attr_accessor :default_method_privacy
def initialize(ruby, file)
@calls = []
@def... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/parser.rb | Ruby | mit | 88 | main | 1,058 | # frozen_string_literal: true
require 'parser'
require 'parser/current'
module Leftovers
module Parser
class << self
# mostly copied from https://github.com/whitequark/parser/blob/master/lib/parser/base.rb
# but with our parser
def parse_with_comments(string, file = '(string)', line = 1)
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/merged_config.rb | Ruby | mit | 88 | main | 2,373 | # frozen_string_literal: true
require 'set'
require 'fast_ignore'
module Leftovers
class MergedConfig
MEMOIZED_IVARS = %i{
@exclude_paths
@include_paths
@test_paths
@precompilers
@dynamic
@keep
@test_only
}.freeze
def initialize(load_defaults: false)
@con... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/file_list.rb | Ruby | mit | 88 | main | 405 | # frozen_string_literal: true
require 'fast_ignore'
module Leftovers
class FileList < ::FastIgnore
def initialize(**arguments)
super(
ignore_rules: ::Leftovers.config.exclude_paths,
include_rules: ::Leftovers.config.include_paths,
root: ::Leftovers.pwd,
**arguments
)
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/config_loader.rb | Ruby | mit | 88 | main | 1,179 | # frozen_string_literal: true
require 'yaml'
module Leftovers
class ConfigLoader
include Autoloader
def self.load(name, path: nil, content: nil)
new(name, path: path, content: content).load
end
attr_reader :name
def initialize(name, path: nil, content: nil)
@name = name
@pat... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/precompilers.rb | Ruby | mit | 88 | main | 1,210 | # frozen_string_literal: true
module Leftovers
module Precompilers
include Autoloader
class << self
def build(precompilers)
precompilers.group_by { |p| build_precompiler(p[:format]) }.map do |format, precompiler|
Precompiler.new(
format,
MatcherBuilders::Path.... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/todo_reporter.rb | Ruby | mit | 88 | main | 2,537 | # frozen_string_literal: true
require 'pathname'
module Leftovers
module TodoReporter
class << self
def prepare
return unless path.exist?
puts "Removing previous #{path.basename} file"
puts ''
path.delete
end
def report(collection)
path.write(generate_... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/definition_collection.rb | Ruby | mit | 88 | main | 1,114 | # frozen_string_literal: true
module Leftovers
class DefinitionCollection
def initialize
@definitions_to_add = {}
@definition_sets_to_add = []
end
def add_definition_node(definition_node)
add(definition_node, loc: definition_node.loc)
end
def add(node, name: node.name, loc: no... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/cli.rb | Ruby | mit | 88 | main | 2,128 | # frozen_string_literal: true
require 'optparse'
module Leftovers
class CLI
def initialize(argv: [])
@argv = argv
end
def run
parse_options
runner.run
rescue ::Leftovers::Error => e
Leftovers.warn("\e[31m#{e.class}: #{e.message}\e[0m\n\n#{e.backtrace.join("\n")}")
1
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/definition_to_add.rb | Ruby | mit | 88 | main | 745 | # frozen_string_literal: true
module Leftovers
class DefinitionToAdd
attr_reader :node, :name, :location
def initialize(node, name: node.name, location: node.loc.name)
@node = node
@name = name
@location = location
end
def privacy=(value)
@node.privacy = value
end
d... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/collection.rb | Ruby | mit | 88 | main | 1,255 | # frozen_string_literal: true
require 'set'
module Leftovers
class Collection
attr_reader :calls, :test_calls, :definitions
def initialize
@calls = []
@test_calls = []
@definitions = []
end
def leftovers
@leftovers ||= begin
freeze_calls
@definitions
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/runner.rb | Ruby | mit | 88 | main | 622 | # frozen_string_literal: true
module Leftovers
class Runner
attr_writer :reporter
def run
reporter.prepare
return reporter.report_success if collection.empty?
reporter.report(collection)
end
def parallel=(value)
collector.parallel = value
end
def progress=(value)
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/comparable_instance.rb | Ruby | mit | 88 | main | 383 | # frozen_string_literal: true
module Leftovers
module ComparableInstance
def eql?(other)
frozen? && other.frozen? &&
self.class == other.class &&
instance_variables.all? do |var|
instance_variable_get(var) == other.instance_variable_get(var)
end
end
alias_method :=... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/definition_node.rb | Ruby | mit | 88 | main | 369 | # frozen_string_literal: true
module Leftovers
class DefinitionNode < AST::Node
attr_reader :name, :path
alias_method :to_sym, :name
def initialize(node, name:, location: node.loc.expression)
@name = name
@path = node.path
@location = location
super(:leftovers_definition)
end... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/precompile_error.rb | Ruby | mit | 88 | main | 616 | # frozen_string_literal: true
module Leftovers
class PrecompileError < Error
attr_reader :line, :column
def initialize(message, line: nil, column: nil, display_class: nil)
@line = line
@column = column
@display_class = display_class
super(message)
end
def warn(path:)
:... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/matchers/node_type.rb | Ruby | mit | 88 | main | 324 | # frozen_string_literal: true
module Leftovers
module Matchers
class NodeType
include ComparableInstance
attr_reader :matcher
def initialize(matcher)
@matcher = matcher
freeze
end
def ===(node)
@matcher === node.type
end
freeze
end
end
... |
github | robotdana/leftovers | https://github.com/robotdana/leftovers | lib/leftovers/matchers/any.rb | Ruby | mit | 88 | main | 369 | # frozen_string_literal: true
module Leftovers
module Matchers
class Any
include ComparableInstance
attr_reader :matchers
def initialize(matchers)
@matchers = matchers
freeze
end
def ===(value)
@matchers.any? do |matcher|
matcher === value
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.