spiker 0.1.0 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6807d10b0e21344ac48f335257b7a92e41cce9ce140b7f73b3f31545d06d7135
4
- data.tar.gz: cd463be9673e5f188459c1ad61e5460dd5b4e9fb05fe6d61651abfd733de1b2c
3
+ metadata.gz: f6183b45c44cffdac7e55a8cc487634185d550b98b88802d331e66b4d19e5159
4
+ data.tar.gz: c96d176df0f11614308af344020b8a3b546e291fcb0dc94b7c97724867a9a6e5
5
5
  SHA512:
6
- metadata.gz: ee478066198cd3b8f3e2bb122d1bd43156dc08a13d2229ad72f1b63f68c67c2ba3d7a6aae8af33d43d319073673228b57dc7ce721b943be61ac8d5c802e2379c
7
- data.tar.gz: e753e0e8618365cd74d7f1ee9a38733a1be9e20102e7ab5c22fdb3693566360ab24d6ea21c5a34e34055b4f60e63de51f76c14804c1ff22e3a3463d2265432ed
6
+ metadata.gz: 61065d34c4b29b1f541ec91274d326536f3952f2e94ed4efad1863bcf81b2eb2b335d140eb9eb2b38ed866ead8bcb213e7b6eff536dc7e71dfe8f9e41507c8a0
7
+ data.tar.gz: fc2d21d8670e09eb8acd314ae5e75c6caf57f6b880e02cc4becebfab2c6d439bb937da3abf464cc22b8a6d34fcad2fdd380a115ebe14706d9d890f168ab89d0e
data/.rubocop.yml CHANGED
@@ -12,6 +12,5 @@ Layout/LineLength:
12
12
  AllCops:
13
13
  NewCops: enable
14
14
  Exclude:
15
- - 'lib/spiker/generators/templates/**'
16
15
  - 'exe/spiker'
17
16
  - 'spiker.gemspec'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spiker (0.1.0)
4
+ spiker (0.1.4)
5
5
  thor (~> 0.19)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,20 +1,12 @@
1
1
  # Spiker
2
2
 
3
- Spiker helps you validate your ideas under test. It can also be a basic educational tool, giving the learner a minimal framework to start writing and testing the Ruby code.
3
+ Spiker helps you validate your ideas under test. It can also be a basic educational tool, giving the learner a minimal framework to start writing and testing their Ruby code.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ [![Gem Version](https://badge.fury.io/rb/spiker.svg)](https://badge.fury.io/rb/spiker)
8
8
 
9
- ```ruby
10
- gem 'spiker'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle install
16
-
17
- Or install it yourself as:
9
+ Install it directly:
18
10
 
19
11
  $ gem install spiker
20
12
 
@@ -29,9 +21,10 @@ Then, create a new spike:
29
21
  $ spiker simple my_spike
30
22
  $ cd my_spike
31
23
 
32
- Using the "simple" formula, Spiker will create an `app.rb` file, a `Gemfile`, and a `Guardfile`. The `app.rb` file will contain boilerplate for both Minitest and a Ruby class in the same file:
24
+ Using the "simple" formula, Spiker will create an `app.rb` file, a `Gemfile`, a `Guardfile` and an `.env` file for configuration, to be read by the `dotenv` gem. The `app.rb` file will contain boilerplate for both Minitest and a Ruby class in the same file:
33
25
 
34
26
  ```ruby
27
+ require 'dotenv'
35
28
  require 'minitest'
36
29
  require 'minitest/autorun'
37
30
  require 'minitest/reporters'
@@ -39,8 +32,12 @@ require 'minitest/reporters'
39
32
  Minitest::Reporters.use!
40
33
 
41
34
  class MySpikeTest < Minitest::Test
42
- def test_that_it_works
43
- assert true
35
+ def test_name
36
+ assert_equal "Fred", MySpike.new(name: "Fred").name
37
+ end
38
+
39
+ def test_default_env_value
40
+ assert_equal "test", ENV["TEST_VALUE"]
44
41
  end
45
42
  end
46
43
 
@@ -54,7 +51,12 @@ end
54
51
 
55
52
  From here, the user should be able to start Guard and immediately begin development in a red-green fashion.
56
53
 
57
- The "multiple" option is not implemented yet, but is intended to flesh out a more complex spike that includes a tests directory and `test_helper.rb`, a `lib` directory, README.md, etc.
54
+ The "multi" option places directories and files into a named directory, and is intended to flesh out a more complex spike that includes a tests directory and `test_helper.rb`, a `lib` directory, README.md, etc. The overall workflow is still the same:
55
+
56
+ $ spiker multi my_spike
57
+ $ cd my_spike
58
+
59
+ Bundle will run automatically and the user will be able to start development in a red-green fashion just the same as with the simple spike. There is also a Rakefile provided, the Guardfile is modified from the simple version to include files in directories, and simple tests are predefined.
58
60
 
59
61
  ## Development
60
62
 
data/lib/spiker/cli.rb CHANGED
@@ -3,11 +3,11 @@
3
3
  require "thor"
4
4
  require_relative "version"
5
5
  require_relative "generators/simple"
6
- require_relative "generators/multiple"
6
+ require_relative "generators/multi"
7
7
 
8
8
  module Spiker
9
- # Accept options "single" and "multiple"
10
- # for single file spikes or multi-file spikes
9
+ # Accept options "single" and "multi"
10
+ # for single-file spikes or multi-file spikes
11
11
  # and a name for the spike directory. That is all
12
12
  class CLI < Thor
13
13
  desc "version", "Show version"
@@ -21,10 +21,10 @@ module Spiker
21
21
  Spiker::Generators::Simple.start([name])
22
22
  end
23
23
 
24
- desc "multiple NAME", "Spike over multiple files"
24
+ desc "multi NAME", "Spike over multiple files"
25
25
  method_option :name, type: :string, aliases: "-n", desc: "Name of the spike"
26
26
  def multiple(name)
27
- Spiker::Generators::Multiple.start([name])
27
+ Spiker::Generators::Multi.start([name])
28
28
  end
29
29
  end
30
30
  end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor/group"
4
+ require_relative "../../spiker"
5
+
6
+ module Spiker
7
+ module Generators
8
+ # Generates multiple spike files, seperating tests from the
9
+ # tested code. For when the spike gets too hairy for a single
10
+ # file.
11
+ class Multi < Thor::Group
12
+ include Thor::Actions
13
+
14
+ argument :name, type: :string
15
+
16
+ def self.source_root
17
+ "#{File.dirname(__FILE__)}/templates"
18
+ end
19
+
20
+ def create_spike_directories
21
+ empty_directory(name)
22
+ empty_directory("#{name}/lib")
23
+ empty_directory("#{name}/test")
24
+ end
25
+
26
+ def create_test_files
27
+ name_in_snake_case = Spiker.snake_case(name)
28
+ name_as_class = Spiker.classify(name)
29
+ opts = { name_as_class: name_as_class, name_in_snake_case: name_in_snake_case }
30
+ template("multi_app_test.rb.erb", "#{name}/test/#{name_in_snake_case}_test.rb", opts)
31
+ template("multi_test_helper.rb", "#{name}/test/test_helper.rb", opts)
32
+ end
33
+
34
+ def create_app_files
35
+ name_in_snake_case = Spiker.snake_case(name)
36
+ opts = { name_as_class: Spiker.classify(name) }
37
+ template("multi_app.rb.erb", "#{name}/lib/#{name_in_snake_case}.rb", opts)
38
+ end
39
+
40
+ def create_guard_file
41
+ template("multi_guardfile.rb", "#{name}/Guardfile")
42
+ end
43
+
44
+ def create_gem_file
45
+ template("multi_gemfile.rb", "#{name}/Gemfile")
46
+ end
47
+
48
+ def create_rake_file
49
+ template("multi_rakefile.rb", "#{name}/Rakefile")
50
+ end
51
+
52
+ def create_readme_file
53
+ opts = { name_as_class: Spiker.classify(name), name: name }
54
+ template("multi_readme.md.erb", "#{name}/README.md", opts)
55
+ end
56
+
57
+ def create_env_file
58
+ template("basic.env", "#{name}/.env")
59
+ end
60
+
61
+ def run_bundler
62
+ inside(name) do
63
+ run("bundle install")
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "thor/group"
4
+ require_relative "../../spiker"
5
+
4
6
  module Spiker
5
7
  module Generators
6
8
  # Generates a single spike file, with supporting infrastructure.
@@ -19,7 +21,8 @@ module Spiker
19
21
  end
20
22
 
21
23
  def create_spike_file
22
- template("simple_app.rb", "#{name}/app.rb")
24
+ opts = { name_as_class: Spiker.classify(name) }
25
+ template("simple_app.rb.erb", "#{name}/app.rb", opts)
23
26
  end
24
27
 
25
28
  def create_guard_file
@@ -30,6 +33,10 @@ module Spiker
30
33
  template("simple_gemfile.rb", "#{name}/Gemfile")
31
34
  end
32
35
 
36
+ def create_env_file
37
+ template("basic.env", "#{name}/.env")
38
+ end
39
+
33
40
  def run_bundler
34
41
  inside(name) do
35
42
  run("bundle install")
@@ -0,0 +1 @@
1
+ TEST_VALUE="test"
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dotenv/load"
4
+
5
+ class <%= config[:name_as_class] %>
6
+ def self.hello
7
+ "Hello, world!"
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class <%= config[:name_as_class] %>Test < MiniTest::Unit::TestCase
6
+ def test_default_class_instantiates
7
+ assert <%= config[:name_as_class] %>.new
8
+ end
9
+
10
+ def test_default_class_responds_to_hello
11
+ assert_equal "Hello, world!", <%= config[:name_as_class] %>.hello
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gem "minitest"
8
+ gem "minitest-reporters"
9
+ gem "guard"
10
+ gem "guard-minitest"
11
+ gem "dotenv"
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ clearing :on
4
+
5
+ guard :minitest, all_after_pass: true do
6
+ # with Minitest::Unit
7
+ watch(%r{^test/(.*)/?(.*)_test\.rb$})
8
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
9
+ watch(%r{^test/test_helper\.rb$}) { "test" }
10
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: %i[test]
@@ -0,0 +1,44 @@
1
+ # <%= config[:name_as_class] %> Spike
2
+
3
+ This is the auto-generated README for the <%= config[:name_as_class] %> spike. This content was generated by the [Spiker](https://github.com/norlinga/spiker) gem.
4
+
5
+ ## Getting Started
6
+
7
+ This directory is the result of **someone** running the following command on a command line:
8
+
9
+ $ gem install spiker
10
+ $ spiker multi <%= config[:name] %>
11
+ $ cd <%= config[:name] %>
12
+
13
+ Once inside the spike directory, open your favorite text editor and then execute the following command:
14
+
15
+ $ bundle install
16
+ $ guard
17
+
18
+ Bundler will have executed once when the spike directory was first created, but it's no problem to run it again (in case the spike directory was shared between machines / environments).
19
+
20
+ After starting Guard you should have been greeted with passing tests. You are now ready to start hashing out your spike under test.
21
+
22
+ ## Adding to This README
23
+
24
+ This README could be a great place to capture findings from your spike. Topics to address in this README might include:
25
+
26
+ - what was the initial motivation for this spike?
27
+ - what is the current state of this spike?
28
+ - is there a future intention or unrealized goal for this spike?
29
+ - what was discovered in the course of this spike?
30
+ - who is involved in this spike?
31
+
32
+ ## Feel Free to Include Code
33
+
34
+ Embedding code in a Markdown file is easy - this README uses the triple backtick syntax. The following code will be rendered as a Ruby code block:
35
+
36
+ ```ruby
37
+ require 'dotenv'
38
+
39
+ puts ENV["TEST_VALUE"]
40
+
41
+ "maybe show some code in your README?".capitalize
42
+ ```
43
+
44
+ Spikes are intended to be short lived, but that's no reason to skip proper practices in your spike development. Have fun!
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ # require the default lib file
5
+ require "<%= config[:name_in_snake_case] %>"
6
+
7
+ require "minitest/autorun"
8
+ require "minitest/reporters"
9
+ require "dotenv/load"
10
+
11
+ Minitest::Reporters.use!
12
+
13
+ # ensure the environment is available
14
+ class DefaultEnvironmentTest < MiniTest::Unit::TestCase
15
+ def test_default_environment
16
+ assert_equal "test", ENV["TEST_VALUE"]
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'dotenv/load'
2
+ require 'minitest'
3
+ require 'minitest/autorun'
4
+ require 'minitest/reporters'
5
+
6
+ Minitest::Reporters.use!
7
+
8
+ class <%= config[:name_as_class] %>Test < Minitest::Test
9
+ def test_name
10
+ assert_equal "Fred", <%= config[:name_as_class] %>.new(name: 'Fred').name
11
+ end
12
+
13
+ def test_default_env_value
14
+ assert_equal "test", ENV["TEST_VALUE"]
15
+ end
16
+ end
17
+
18
+ class <%= config[:name_as_class] %>
19
+ attr_accessor :name
20
+ def initialize(name:)
21
+ @name = name
22
+ end
23
+ end
@@ -4,8 +4,10 @@ source "https://rubygems.org"
4
4
 
5
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
- gem 'minitest'
8
- gem 'minitest-reporters'
7
+ gem "minitest"
8
+ gem "minitest-reporters"
9
9
 
10
- gem 'guard'
11
- gem 'guard-minitest'
10
+ gem "guard"
11
+ gem "guard-minitest"
12
+
13
+ gem "dotenv"
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  clearing :on
2
4
 
3
- guard :minitest, all_after_pass: true, test_folders: ['.'], test_file_patterns: '*.rb' do
5
+ guard :minitest, all_after_pass: true, test_folders: ["."], test_file_patterns: "*.rb" do
4
6
  # with Minitest::Unit
5
- watch(%r{^app\.rb$}) { './app.rb' }
7
+ watch(/^app\.rb$/) { "./app.rb" }
6
8
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spiker
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/spiker.rb CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  require_relative "spiker/version"
4
4
 
5
+ # Spiker is a simple spike generator.
5
6
  module Spiker
6
7
  class Error < StandardError; end
8
+
9
+ def self.classify(str)
10
+ str.split(/[^A-Za-z0-0]/).map(&:capitalize).join
11
+ end
12
+
13
+ def self.snake_case(str)
14
+ # lifted from ActiveSupport inflectors
15
+ str.gsub(/::/, "/")
16
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
17
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
18
+ .tr("-", "_")
19
+ .downcase
20
+ end
7
21
  end
data/spiker.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = "Properly spike your Ruby"
12
12
  spec.description = "Scaffold for code spikes, includes simple boilerplate with Minitest + Guard to make red/green work out-of-the-box."
13
- spec.homepage = "http://github.com/norling/spiker."
13
+ spec.homepage = "http://github.com/norlinga/spiker"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spiker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Norling
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-19 00:00:00.000000000 Z
11
+ date: 2022-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -47,19 +47,27 @@ files:
47
47
  - exe/spiker
48
48
  - lib/spiker.rb
49
49
  - lib/spiker/cli.rb
50
- - lib/spiker/generators/multiple.rb
50
+ - lib/spiker/generators/multi.rb
51
51
  - lib/spiker/generators/simple.rb
52
- - lib/spiker/generators/templates/simple_app.rb
52
+ - lib/spiker/generators/templates/basic.env
53
+ - lib/spiker/generators/templates/multi_app.rb.erb
54
+ - lib/spiker/generators/templates/multi_app_test.rb.erb
55
+ - lib/spiker/generators/templates/multi_gemfile.rb
56
+ - lib/spiker/generators/templates/multi_guardfile.rb
57
+ - lib/spiker/generators/templates/multi_rakefile.rb
58
+ - lib/spiker/generators/templates/multi_readme.md.erb
59
+ - lib/spiker/generators/templates/multi_test_helper.rb
60
+ - lib/spiker/generators/templates/simple_app.rb.erb
53
61
  - lib/spiker/generators/templates/simple_gemfile.rb
54
62
  - lib/spiker/generators/templates/simple_guardfile.rb
55
63
  - lib/spiker/version.rb
56
64
  - spiker.gemspec
57
- homepage: http://github.com/norling/spiker.
65
+ homepage: http://github.com/norlinga/spiker
58
66
  licenses:
59
67
  - MIT
60
68
  metadata:
61
69
  allowed_push_host: https://rubygems.org
62
- homepage_uri: http://github.com/norling/spiker.
70
+ homepage_uri: http://github.com/norlinga/spiker
63
71
  source_code_uri: https://github.com/norlinga/spiker
64
72
  changelog_uri: https://github.com/norlinga/spiker
65
73
  post_install_message:
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "thor/group"
4
- module Spiker
5
- module Generators
6
- # Generates multiple spike files, seperating tests from the
7
- # tested code. For when the spike gets too hairy for a single
8
- # file.
9
- class Multiple < Thor::Group
10
- include Thor::Actions
11
-
12
- argument :name, type: :string
13
- end
14
- end
15
- end
@@ -1,18 +0,0 @@
1
- require 'minitest'
2
- require 'minitest/autorun'
3
- require 'minitest/reporters'
4
-
5
- Minitest::Reporters.use!
6
-
7
- class <%= name.capitalize %>Test < Minitest::Test
8
- def test_that_it_works
9
- assert true
10
- end
11
- end
12
-
13
- class <%= name.capitalize %>
14
- attr_accessor :name
15
- def initialize(name:)
16
- @name = name
17
- end
18
- end