Skip to content

Commit

Permalink
update to use modern ruby
Browse files Browse the repository at this point in the history
fix for travis

update ruby versions on travis, skip unworkable rubies for rails 6.0

apparently you need development gems, huh
  • Loading branch information
marcinruszkiewicz committed Oct 3, 2019
1 parent 844276c commit 747371d
Show file tree
Hide file tree
Showing 35 changed files with 120 additions and 283 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@
*.o
*.a
mkmf.log

.rspec_status
gemfiles/*.lock
spec/support/rails_test_app/db/*.sqlite3
spec/support/rails_test_app/db/*.sqlite3-journal
spec/support/rails_test_app/log/*.log
spec/support/rails_test_app/tmp/
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--color
--warnings
--require spec_helper
--pattern "spec/*_spec.rb"
31 changes: 12 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
language: ruby

bundler_args: --without development

script: script/test
gemfile: spec/support/rails_test_app/Gemfile

rvm:
- 2.1.0
- ruby-head
- jruby-head
- rbx

- 2.3.8
- 2.4.7
- 2.5.6
- 2.6.4
gemfile:
- gemfiles/5.2.gemfile
- gemfiles/6.0.gemfile
matrix:
allow_failures:
- rvm: 2.0.0
- rvm: ruby-head
- rvm: jruby-head
- rvm: rbx

branches:
only:
- master
exclude:
- rvm: 2.3.8
gemfile: gemfiles/6.0.gemfile
- rvm: 2.4.7
gemfile: gemfiles/6.0.gemfile
11 changes: 11 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

appraise '5.2' do
gem 'rails', '~> 5.2.0'
gem 'sqlite3'
end

appraise '6.0' do
gem 'rails', '~> 6.0.0'
gem 'sqlite3'
end
34 changes: 5 additions & 29 deletions bin/zapata
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
#!/usr/bin/env ruby
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require_relative '../lib/zapata'
require 'rubygems'
require 'bundler/setup'
require 'zapata'
require 'zapata/cli'

description_of_generate = "'zapata generate <filename>'
-s, --single option to skip app/models analysis"

slop = Slop.new(help: true, banner: true) do
banner('Usage: zapata [options]')
on :v, :version, 'Print version.' do
puts "Your version is #{Zapata::VERSION}"
end

command('generate', description: description_of_generate) do
on(:s, :single, "Does not analyze 'app/models'", banner: true)

run do |opts, args|
Zapata::Revolutionist.generate_with_friendly_output(args, opts)
end
end

run do |opts, args|
if args.present?
Zapata::Revolutionist.generate_with_friendly_output(args, opts)
end
end
end

puts slop.help if ARGV.empty?
slop.parse
Zapata::CLI.start(ARGV)
12 changes: 12 additions & 0 deletions gemfiles/5.2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 5.2.0"
gem "sqlite3"

group :test do
gem "coveralls", require: false
end

gemspec path: "../"
12 changes: 12 additions & 0 deletions gemfiles/6.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 6.0.0"
gem "sqlite3"

group :test do
gem "coveralls", require: false
end

gemspec path: "../"
10 changes: 4 additions & 6 deletions lib/zapata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
require 'open3'
require 'rspec'
require 'memoist'
require 'slop'

require_rel 'zapata/core'
require_rel 'zapata/predictor'
require_rel 'zapata/primitive/base'
require_rel 'zapata/primitive'
require_rel 'zapata/rzpec'
require_relative 'zapata/analyst'
Expand All @@ -23,14 +23,12 @@ class Revolutionist
class << self
attr_accessor :analysis, :analysis_as_array

def generate_with_friendly_output(args, opts)
file = args.shift
spec_filename = Zapata::Revolutionist.generate(file,
single: single?(opts, args))
def generate_with_friendly_output(filename:, single: false)
spec_filename = Zapata::Revolutionist.generate(filename: filename, single: single)
puts "Its done, comrades. File #{spec_filename} was generated."
end

def generate(filename, single: false)
def generate(filename:, single: false)
dirs = single ? [] : %w(app/models)
file_list = Core::Collector.expand_dirs_to_files(dirs)
new(file_list).generate_rspec_for(filename, spec_filename(filename))
Expand Down
15 changes: 15 additions & 0 deletions lib/zapata/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'thor'
require_relative 'version'

module Zapata
class CLI < Thor

desc 'generate FILENAME', 'generate spec file for model'
option :single, type: :boolean, desc: 'skip app/models analysis', aliases: :s
def generate(filename)
Zapata::Revolutionist.generate_with_friendly_output(filename: filename, single: options[:single])
end
end
end
2 changes: 1 addition & 1 deletion lib/zapata/primitive/defs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def public?
end

def node
receiver, name, args, body = @code.to_a
_, name, args, body = @code.to_a
type = @code.type
OpenStruct.new(type: type, name: name, args: args, body: body)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/zapata/primitive/klass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def parent_modul_names
end

def node
const, inherited_from_klass, body = @code.to_a
const, _, body = @code.to_a
immediate_modul, klass = const.to_a
chain = parent_modul_names + [immediate_modul, klass]
name = chain.compact.join('::')
Expand Down
2 changes: 1 addition & 1 deletion lib/zapata/primitive/sklass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(code)
end

def node
receiver_self, body = @code.to_a
_, body = @code.to_a
type = @code.type

OpenStruct.new(type: type, body: body)
Expand Down
1 change: 0 additions & 1 deletion lib/zapata/printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def hash(given)
values = unnested.map do |key, val|
print_hash_pair(key, val, all_keys_symbols?(unnested))
end

"{ #{values.join(', ')} }"
end

Expand Down
2 changes: 0 additions & 2 deletions spec/array_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'spec_helper'

describe Zapata::Revolutionist do
before(:all) do
@generated = exec_generation('app/models/test_array.rb')
Expand Down
2 changes: 0 additions & 2 deletions spec/definition_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'spec_helper'

describe Zapata::Revolutionist do
before(:all) do
@generated = exec_generation('app/models/test_definition.rb')
Expand Down
36 changes: 0 additions & 36 deletions spec/generation_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'spec_helper'

describe Zapata::Revolutionist do
describe '#generate_with_friendly_output' do
let(:file_name) { 'app/models/test_array.rb' }
Expand All @@ -20,39 +18,5 @@
end
end
end

context 'without the generate command' do
context 'with single (-s) specified' do
it 'returns a single file generation message' do
output = execution_output("cd #{RAILS_TEST_APP_DIR} && bundle exec zapata #{file_name} -s")
expect(output.count).to eq 1
expect(output.first).to eq "Its done, comrades. File spec/models/test_array_spec.rb was generated.\n"
end
end

context 'with single (--single) specified' do
it 'returns a single file generation message' do
output = execution_output("cd #{RAILS_TEST_APP_DIR} && bundle exec zapata #{file_name} --single")
expect(output.count).to eq 1
expect(output.first).to eq "Its done, comrades. File spec/models/test_array_spec.rb was generated.\n"
end
end

context 'with no single specified' do
it 'returns multiple file generation messages' do
output = execution_output("cd #{RAILS_TEST_APP_DIR} && bundle exec zapata #{file_name}")
expect(output.count).to be > 1
end
end
end

def execution_output(command)
stdout = Bundler.with_clean_env do
Open3.pipeline_r(
command
)
end
stdout.first.readlines
end
end
end
4 changes: 1 addition & 3 deletions spec/hash_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'spec_helper'

describe Zapata::Revolutionist do
before(:all) do
@generated = exec_generation('app/models/test_hash.rb')
Expand Down Expand Up @@ -37,7 +35,7 @@

it '#test_keys_are_symbols' do
has_block('#test_keys_are_symbols', %{
expect(test_hash.test_keys_are_symbols({ this: 'should', be: 'pretty' })).to eq({ this: 'should', be: 'pretty' })
expect(test_hash.test_keys_are_symbols({ this: 'should', be: 'pretty' })).to eq({ be: 'pretty', this: 'should' })
})
end
end
2 changes: 0 additions & 2 deletions spec/klass_types_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'spec_helper'

describe Zapata::Revolutionist do
context 'it should work with' do
it 'bare module' do
Expand Down
2 changes: 0 additions & 2 deletions spec/send_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'spec_helper'

describe Zapata::Revolutionist do
before(:all) do
@generated = exec_generation('app/models/test_send.rb')
Expand Down
2 changes: 0 additions & 2 deletions spec/simple_types_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'spec_helper'

describe Zapata::Revolutionist do
context 'it should work with' do
it 'ints' do
Expand Down

0 comments on commit 747371d

Please sign in to comment.