├── .gitignore ├── .rspec ├── .semaphore └── semaphore.yml ├── CODE_OF_CONDUCT.md ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── bin ├── console └── setup ├── exe └── goku ├── goku.gemspec ├── lib ├── goku.rb └── goku │ ├── cli.rb │ ├── path.rb │ ├── ruby.rb │ ├── ruby │ ├── base.rb │ ├── class.rb │ ├── method.rb │ ├── method_spec.rb │ ├── module.rb │ └── spec.rb │ └── version.rb └── spec ├── goku_spec.rb ├── lib └── goku │ ├── path_spec.rb │ ├── ruby │ ├── base_spec.rb │ ├── class_spec.rb │ ├── method_spec.rb │ ├── method_spec_spec.rb │ ├── module_spec.rb │ └── spec_spec.rb │ └── ruby_spec.rb └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | .byebug_history 11 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | -------------------------------------------------------------------------------- /.semaphore/semaphore.yml: -------------------------------------------------------------------------------- 1 | version: "v1.0-beta-task" 2 | name: First pipeline example 3 | agent: 4 | machine: 5 | type: e1-standard-2 6 | os_image: ubuntu1404 7 | 8 | blocks: 9 | - name: "Build" 10 | task: 11 | env_vars: 12 | - name: APP_ENV 13 | value: prod 14 | jobs: 15 | - name: Docker build 16 | commands: 17 | - checkout 18 | - ls -1 19 | - sleep 301 20 | - echo $APP_ENV 21 | - echo "Docker build..." 22 | - echo "done" 23 | 24 | - name: "Smoke tests" 25 | task: 26 | jobs: 27 | - name: Smoke 28 | commands: 29 | - checkout 30 | - echo "make smoke" 31 | 32 | - name: "Unit tests" 33 | task: 34 | jobs: 35 | - name: RSpec 36 | commands: 37 | - checkout 38 | - echo "make rspec" 39 | 40 | - name: Lint code 41 | commands: 42 | - checkout 43 | - echo "make lint" 44 | 45 | - name: Check security 46 | commands: 47 | - checkout 48 | - echo "make security" 49 | 50 | - name: "Integration tests" 51 | task: 52 | jobs: 53 | - name: Cucumber 54 | commands: 55 | - checkout 56 | - echo "make cucumber" 57 | 58 | - name: "Push Image" 59 | task: 60 | jobs: 61 | - name: Push 62 | commands: 63 | - checkout 64 | - echo "make docker.push" 65 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of 4 | fostering an open and welcoming community, we pledge to respect all people who 5 | contribute through reporting issues, posting feature requests, updating 6 | documentation, submitting pull requests or patches, and other activities. 7 | 8 | We are committed to making participation in this project a harassment-free 9 | experience for everyone, regardless of level of experience, gender, gender 10 | identity and expression, sexual orientation, disability, personal appearance, 11 | body size, race, ethnicity, age, religion, or nationality. 12 | 13 | Examples of unacceptable behavior by participants include: 14 | 15 | * The use of sexualized language or imagery 16 | * Personal attacks 17 | * Trolling or insulting/derogatory comments 18 | * Public or private harassment 19 | * Publishing other's private information, such as physical or electronic 20 | addresses, without explicit permission 21 | * Other unethical or unprofessional conduct 22 | 23 | Project maintainers have the right and responsibility to remove, edit, or 24 | reject comments, commits, code, wiki edits, issues, and other contributions 25 | that are not aligned to this Code of Conduct, or to ban temporarily or 26 | permanently any contributor for other behaviors that they deem inappropriate, 27 | threatening, offensive, or harmful. 28 | 29 | By adopting this Code of Conduct, project maintainers commit themselves to 30 | fairly and consistently applying these principles to every aspect of managing 31 | this project. Project maintainers who do not follow or enforce the Code of 32 | Conduct may be permanently removed from the project team. 33 | 34 | This code of conduct applies both within project spaces and in public spaces 35 | when an individual is representing the project or its community. 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 38 | reported by contacting a project maintainer at igor@renderedtext.com. All 39 | complaints will be reviewed and investigated and will result in a response that 40 | is deemed necessary and appropriate to the circumstances. Maintainers are 41 | obligated to maintain confidentiality with regard to the reporter of an 42 | incident. 43 | 44 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 45 | version 1.3.0, available at 46 | [http://contributor-covenant.org/version/1/3/0/][version] 47 | 48 | [homepage]: http://contributor-covenant.org 49 | [version]: http://contributor-covenant.org/version/1/3/0/ -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in goku.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Igor Šarčević 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Goku - The saiyan class generator 2 | 3 | [![Gem Version](https://badge.fury.io/rb/goku.svg)](https://badge.fury.io/rb/goku) 4 | [![Build Status](https://semaphoreci.com/api/v1/shiroyasha/goku/branches/master/badge.svg)](https://semaphoreci.com/shiroyasha/goku) 5 | 6 | 308 7 | 8 | ![goku](http://img12.deviantart.net/ee76/i/2016/039/7/2/goku_vs_beerus_drawing_by_pikachustar93-d9ladzb.png) 9 | 10 | ## Installation 11 | 12 | Add this line to your application's Gemfile: 13 | 14 | ```ruby 15 | gem 'goku' 16 | ``` 17 | 18 | And then execute: 19 | 20 | $ bundle 21 | 22 | Or install it yourself as: 23 | 24 | $ gem install goku 25 | 26 | ## Usage 27 | 28 | ``` sh 29 | $ goku class lib/users/signup.rb 30 | Creating lib/users/signup.rb 31 | Creating spec/lib/users/signup_spec.rb 32 | ``` 33 | 34 | Creates a class in `lib/users/signup.rb`: 35 | 36 | ``` ruby 37 | module Users 38 | class Signup 39 | 40 | def initialize 41 | end 42 | 43 | end 44 | end 45 | ``` 46 | 47 | And a RSpec test file `spec/lib/users/signup_spec.rb`: 48 | 49 | ``` ruby 50 | require "spec_helper" 51 | 52 | describe Users::Signup do 53 | 54 | end 55 | ``` 56 | ## Development 57 | 58 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. 59 | 60 | To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). 61 | 62 | ## Contributing 63 | 64 | Bug reports and pull requests are welcome on GitHub at https://github.com/shiroyasha/goku. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. 65 | 66 | Also if you don't like Dragon Ball then GTFO. 67 | 68 | ## License 69 | 70 | The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). 71 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rspec/core/rake_task" 3 | 4 | RSpec::Core::RakeTask.new(:spec) 5 | 6 | task :default => :spec 7 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "goku" 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | # (If you use this, don't forget to add pry to your Gemfile!) 10 | # require "pry" 11 | # Pry.start 12 | 13 | require "irb" 14 | IRB.start 15 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /exe/goku: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "goku" 4 | 5 | Goku::CLI.start(ARGV) 6 | -------------------------------------------------------------------------------- /goku.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'goku/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "goku" 8 | spec.version = Goku::VERSION 9 | spec.authors = ["Igor Šarčević"] 10 | spec.email = ["igor@renderedtext.com"] 11 | 12 | spec.summary = %q{Goku - The saiyan class generator} 13 | spec.homepage = "https://github.com/shiroyasha/goku" 14 | spec.license = "MIT" 15 | 16 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 17 | spec.bindir = "exe" 18 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 19 | spec.require_paths = ["lib"] 20 | 21 | spec.add_dependency "thor", "~> 0.19" 22 | spec.add_dependency "activesupport", "~> 4.2" 23 | spec.add_dependency "colorize", "~> 0.7" 24 | 25 | spec.add_development_dependency "bundler", "~> 1.11" 26 | spec.add_development_dependency "rake", "~> 10.0" 27 | spec.add_development_dependency "rspec", "~> 3.0" 28 | spec.add_development_dependency "byebug", "~> 5.0" 29 | end 30 | -------------------------------------------------------------------------------- /lib/goku.rb: -------------------------------------------------------------------------------- 1 | require "thor" 2 | require "active_support/all" 3 | require "fileutils" 4 | require "colorize" 5 | 6 | require "goku/ruby" 7 | 8 | require "goku/path" 9 | require "goku/version" 10 | 11 | module Goku 12 | require_relative "goku/cli" 13 | end 14 | -------------------------------------------------------------------------------- /lib/goku/cli.rb: -------------------------------------------------------------------------------- 1 | module Goku 2 | class CLI < Thor 3 | 4 | desc "c PATH", "Create a class" 5 | def c(raw_path) 6 | path = Goku::Path.new(raw_path) 7 | ruby = Goku::Ruby.new(path) 8 | 9 | implementation = ruby.create_class.to_s 10 | spec = ruby.create_spec.to_s 11 | 12 | save(path, implementation, spec) 13 | end 14 | 15 | desc "m PATH", "Create a module" 16 | def m(raw_path) 17 | path = Goku::Path.new(raw_path) 18 | ruby = Goku::Ruby.new(path) 19 | 20 | implementation = ruby.create_module.to_s 21 | spec = ruby.create_spec.to_s 22 | 23 | save(path, implementation, spec) 24 | end 25 | 26 | map "module" => "m" 27 | map "class" => "c" 28 | 29 | private 30 | 31 | def save(path, implementation, spec) 32 | failure("File #{path.full.colorize(:red)} already exists") if path.exists? 33 | failure("File #{path.to_spec.full.colorize(:red)} already exists") if path.to_spec.exists? 34 | 35 | puts "Creating #{path.full.colorize(:green)}" 36 | path.write(implementation) 37 | 38 | puts "Creating #{path.to_spec.full.colorize(:green)}" 39 | path.to_spec.write(spec) 40 | end 41 | 42 | def failure(message) 43 | puts message 44 | 45 | exit(1) 46 | end 47 | 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /lib/goku/path.rb: -------------------------------------------------------------------------------- 1 | module Goku 2 | class PathConversionError < StandardError; end 3 | 4 | class Path 5 | attr_reader :full 6 | 7 | def initialize(raw_path) 8 | @full= raw_path 9 | end 10 | 11 | def write(content) 12 | FileUtils.mkdir_p(File.dirname(full)) 13 | 14 | File.write(full, "#{content}\n") 15 | end 16 | 17 | def exists? 18 | File.exists?(full) 19 | end 20 | 21 | def directories 22 | File.dirname(full).split("/") 23 | end 24 | 25 | def filename 26 | File.basename(full, extension) 27 | end 28 | 29 | def extension 30 | File.extname(full) 31 | end 32 | 33 | def spec? 34 | directories.first == "spec" 35 | end 36 | 37 | def implementation? 38 | !spec? 39 | end 40 | 41 | def to_spec 42 | raise Goku::PathConversionError.new("Path is already a specification") if spec? 43 | 44 | Goku::Path.new(File.join(["spec", directories, "#{filename}_spec#{extension}"])) 45 | end 46 | 47 | def to_implementation 48 | raise Goku::PathConversionError.new("Path is already an implementation") if implementation? 49 | 50 | Goku::Path.new(File.join([directories.drop(1), "#{filename.gsub(/_spec$/, "")}#{extension}"])) 51 | end 52 | 53 | alias :test? :spec? 54 | 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /lib/goku/ruby.rb: -------------------------------------------------------------------------------- 1 | module Goku 2 | class Ruby 3 | require_relative "ruby/base" 4 | require_relative "ruby/method" 5 | require_relative "ruby/class" 6 | require_relative "ruby/module" 7 | require_relative "ruby/spec" 8 | require_relative "ruby/method_spec" 9 | 10 | attr_reader :path 11 | 12 | def initialize(path) 13 | @path = path 14 | end 15 | 16 | def create_class 17 | nested(Goku::Ruby::Class.new(path.filename)) 18 | end 19 | 20 | def create_module 21 | nested(Goku::Ruby::Module.new(path.filename)) 22 | end 23 | 24 | def create_spec 25 | Goku::Ruby::Spec.new(path.filename, ancestor_names) 26 | end 27 | 28 | def ancestors 29 | @ancestors ||= ancestor_names.map { |m| Goku::Ruby::Module.new(m) } 30 | end 31 | 32 | def ancestor_names 33 | @ancestor_names ||= @path.directories.drop(1) 34 | end 35 | 36 | def nested(element) 37 | elements = ancestors << element 38 | 39 | elements.each_cons(2) { |parent, sub| parent.add(sub) } 40 | 41 | elements.first 42 | end 43 | 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /lib/goku/ruby/base.rb: -------------------------------------------------------------------------------- 1 | module Goku 2 | class Ruby 3 | class Base 4 | 5 | attr_reader :name 6 | attr_reader :elements 7 | 8 | def initialize(name) 9 | @name = name 10 | @elements = [] 11 | end 12 | 13 | def add(element) 14 | @elements << element 15 | end 16 | 17 | def to_s 18 | elements.map(&:to_s).map { |el| el.indent(2) }.join 19 | end 20 | 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/goku/ruby/class.rb: -------------------------------------------------------------------------------- 1 | module Goku 2 | class Ruby 3 | class Class < Base 4 | 5 | def initialize(name) 6 | super 7 | 8 | initializer = Goku::Ruby::Method.new("initialize") 9 | 10 | add(initializer) 11 | end 12 | 13 | def to_s 14 | "class #{name.camelcase}\n#{super}\nend" 15 | end 16 | 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/goku/ruby/method.rb: -------------------------------------------------------------------------------- 1 | module Goku 2 | class Ruby 3 | class Method < Base 4 | 5 | def to_s 6 | "\ndef #{name}\nend\n" 7 | end 8 | 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/goku/ruby/method_spec.rb: -------------------------------------------------------------------------------- 1 | module Goku 2 | class Ruby 3 | class MethodSpec < Base 4 | 5 | def to_s 6 | "\ndescribe \"##{name}\" do\nend\n" 7 | end 8 | 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/goku/ruby/module.rb: -------------------------------------------------------------------------------- 1 | module Goku 2 | class Ruby 3 | class Module < Base 4 | 5 | def to_s 6 | "module #{name.camelcase}\n#{super}\nend" 7 | end 8 | 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/goku/ruby/spec.rb: -------------------------------------------------------------------------------- 1 | module Goku 2 | class Ruby 3 | class Spec < Base 4 | 5 | def initialize(name, ancestor_names) 6 | super(name) 7 | 8 | @ancestor_names = ancestor_names 9 | end 10 | 11 | def to_s 12 | full_name = (@ancestor_names + [name]).map(&:camelcase).join("::") 13 | 14 | "require \"spec_helper\"\n\ndescribe #{full_name} do\n#{super}\nend" 15 | end 16 | 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/goku/version.rb: -------------------------------------------------------------------------------- 1 | module Goku 2 | VERSION = "1.2" 3 | end 4 | -------------------------------------------------------------------------------- /spec/goku_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe Goku do 4 | it "has a version number" do 5 | expect(Goku::VERSION).not_to be nil 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/lib/goku/path_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe Goku::Path do 4 | let(:implementation) { described_class.new("lib/goku/builders/class_builder.rb") } 5 | let(:spec) { described_class.new("spec/lib/goku/builders/class_builder_spec.rb") } 6 | 7 | describe "#directories" do 8 | subject { implementation } 9 | 10 | it "returns all the directories in the path" do 11 | expect(subject.directories).to eq([ 12 | "lib", 13 | "goku", 14 | "builders" 15 | ]) 16 | end 17 | end 18 | 19 | describe "#filename" do 20 | subject { implementation } 21 | 22 | it "returns the name of the file" do 23 | expect(subject.filename).to eq("class_builder") 24 | end 25 | end 26 | 27 | describe "#extension" do 28 | subject { implementation } 29 | 30 | it "returns the name of the file" do 31 | expect(subject.extension).to eq(".rb") 32 | end 33 | end 34 | 35 | describe "#spec?" do 36 | context "when the path is a spec file" do 37 | it { expect(spec).to be_spec } 38 | end 39 | 40 | context "when the path is not a spec file" do 41 | it { expect(implementation).to_not be_spec } 42 | end 43 | end 44 | 45 | describe "#test?" do 46 | context "when the path is a spec file" do 47 | it { expect(spec).to be_test } 48 | end 49 | 50 | context "when the path is not a spec file" do 51 | it { expect(implementation).to_not be_test } 52 | end 53 | end 54 | 55 | describe "#implementation?" do 56 | context "when the path is a spec file" do 57 | it { expect(spec).to_not be_implementation } 58 | end 59 | 60 | context "when the path is not a spec file" do 61 | it { expect(implementation).to be_implementation } 62 | end 63 | end 64 | 65 | describe "#to_spec" do 66 | context "when the path is a spec file" do 67 | it { expect { spec.to_spec }.to raise_exception(Goku::PathConversionError) } 68 | end 69 | 70 | context "when the path is an implementation file" do 71 | it { expect(implementation.to_spec.full).to eq(spec.full) } 72 | end 73 | end 74 | 75 | describe "#to_implementation" do 76 | context "when the path is an implementation file" do 77 | it { expect { implementation.to_implementation }.to raise_exception(Goku::PathConversionError) } 78 | end 79 | 80 | context "when the path is a spec file" do 81 | it { expect(spec.to_implementation.full).to eq(implementation.full) } 82 | end 83 | end 84 | 85 | end 86 | -------------------------------------------------------------------------------- /spec/lib/goku/ruby/base_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe Goku::Ruby::Base do 4 | 5 | subject { described_class.new("user") } 6 | 7 | describe "#add" do 8 | it "add a subelement to the element" do 9 | expect(subject.elements).to eq([]) 10 | 11 | element = described_class.new("test") 12 | 13 | subject.add(element) 14 | 15 | expect(subject.elements).to include(element) 16 | end 17 | end 18 | 19 | describe "to_s" do 20 | let(:initialize_method) { Goku::Ruby::Method.new(:initialize) } 21 | 22 | it "includes the subelement in the class" do 23 | subject.add(initialize_method) 24 | 25 | expect(subject.to_s).to include("def initialize") 26 | end 27 | 28 | it "indents the method in the class" do 29 | subject.add(initialize_method) 30 | 31 | expect(subject.to_s).to include(" def") 32 | end 33 | end 34 | 35 | end 36 | -------------------------------------------------------------------------------- /spec/lib/goku/ruby/class_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe Goku::Ruby::Class do 4 | 5 | subject { described_class.new("user_controller") } 6 | 7 | it "has an initializer method" do 8 | expect(subject.elements.map(&:name)).to include("initialize") 9 | end 10 | 11 | describe "to_s" do 12 | it "converts the name of the class to a constant" do 13 | expect(subject.to_s).to include("UserController") 14 | end 15 | 16 | it "creates a header" do 17 | expect(subject.to_s).to include("class UserController") 18 | end 19 | 20 | it "add an 'end' clause" do 21 | expect(subject.to_s).to include("end") 22 | end 23 | end 24 | 25 | end 26 | -------------------------------------------------------------------------------- /spec/lib/goku/ruby/method_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe Goku::Ruby::Method do 4 | 5 | subject { described_class.new("initialize") } 6 | 7 | describe "to_s" do 8 | it "creates a header" do 9 | expect(subject.to_s).to include("def initialize") 10 | end 11 | 12 | it "add extra spaces around the definition" do 13 | expect(subject.to_s).to match("\ndef") 14 | expect(subject.to_s).to match("end\n") 15 | end 16 | 17 | it "add an 'end' clause" do 18 | expect(subject.to_s).to include("end") 19 | end 20 | end 21 | 22 | end 23 | -------------------------------------------------------------------------------- /spec/lib/goku/ruby/method_spec_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe Goku::Ruby::MethodSpec do 4 | 5 | subject { described_class.new("log_out!") } 6 | 7 | describe "to_s" do 8 | it "creates a header" do 9 | expect(subject.to_s).to include('describe "#log_out!" do') 10 | end 11 | 12 | it "add extra spaces around the definition" do 13 | expect(subject.to_s).to match("\ndescribe") 14 | expect(subject.to_s).to match("end\n") 15 | end 16 | 17 | it "add an 'end' clause" do 18 | expect(subject.to_s).to include("end") 19 | end 20 | end 21 | 22 | end 23 | -------------------------------------------------------------------------------- /spec/lib/goku/ruby/module_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe Goku::Ruby::Module do 4 | 5 | subject { described_class.new("user_helper") } 6 | 7 | describe "to_s" do 8 | it "converts the name of the module to a constant" do 9 | expect(subject.to_s).to include("UserHelper") 10 | end 11 | 12 | it "creates a header" do 13 | expect(subject.to_s).to include("module UserHelper") 14 | end 15 | 16 | it "add an 'end' clause" do 17 | expect(subject.to_s).to include("end") 18 | end 19 | end 20 | 21 | end 22 | -------------------------------------------------------------------------------- /spec/lib/goku/ruby/spec_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe Goku::Ruby::Spec do 4 | 5 | subject { described_class.new("user_helper", ["goku", "elements"]) } 6 | 7 | describe "to_s" do 8 | it "converts the name of the module to a constant" do 9 | expect(subject.to_s).to include("Goku::Elements::UserHelper") 10 | end 11 | 12 | it "requires spec_helper" do 13 | expect(subject.to_s).to include("require \"spec_helper\"") 14 | end 15 | 16 | it "creates a header" do 17 | expect(subject.to_s).to include("describe Goku::Elements::UserHelper do") 18 | end 19 | 20 | it "add an 'end' clause" do 21 | expect(subject.to_s).to include("end") 22 | end 23 | end 24 | 25 | end 26 | -------------------------------------------------------------------------------- /spec/lib/goku/ruby_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe Goku::Ruby do 4 | let(:path) { Goku::Path.new("lib/goku/something/test.rb") } 5 | subject { described_class.new(path) } 6 | 7 | describe "#ancestor_names" do 8 | it "lists all the ancestors" do 9 | expect(subject.ancestor_names).to include "goku" 10 | expect(subject.ancestor_names).to include "something" 11 | end 12 | 13 | it "sorts the ancestors from the top to the bottom" do 14 | expect(subject.ancestor_names.last).to eq "something" 15 | expect(subject.ancestor_names.first).to eq "goku" 16 | end 17 | end 18 | 19 | describe "#ancestors" do 20 | it "returns a list of modules" do 21 | subject.ancestors.each do |ancestor| 22 | expect(ancestor).to be_instance_of(Goku::Ruby::Module) 23 | end 24 | end 25 | 26 | it "creates a module for each ancestor name" do 27 | expect(subject.ancestors.map(&:name)).to match_array(subject.ancestor_names) 28 | end 29 | end 30 | 31 | describe "#nested" do 32 | let(:klass) { Goku::Ruby::Class.new("test") } 33 | 34 | it "returns the top ancestor" do 35 | expect(subject.nested(klass).name).to eq("goku") 36 | end 37 | 38 | it "nests the element under the deepest ancestor" do 39 | goku = subject.nested(klass) 40 | something = goku.elements.first 41 | test = something.elements.first 42 | 43 | expect(test).to eq klass 44 | end 45 | 46 | context "when there are no ancestors" do 47 | it "returns the passed element" do 48 | ruby = described_class.new(Goku::Path.new("lib/test.rb")) 49 | 50 | klass = Goku::Ruby::Class.new("test") 51 | 52 | expect(ruby.nested(klass)).to eq(klass) 53 | end 54 | end 55 | end 56 | 57 | end 58 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 2 | require 'goku' 3 | require "byebug" 4 | --------------------------------------------------------------------------------