From c05bdca25899d8892329b08e0cdb6f9e32277434 Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <the@jeffreyfreeman.me> Date: Fri, 11 Aug 2023 10:18:23 -0400 Subject: [PATCH] Got rspec framework working and started refactoring --- .gitignore | 1 + .rspec | 1 + Rakefile | 47 +++++---- features/kiss.feature | 6 -- features/step_definitions/kiss_steps.rb | 1 - features/support/env.rb | 15 --- kiss-tnc.gemspec | 14 +-- spec/kiss/app_info_spec.rb | 12 +++ spec/spec_helper.rb | 132 ++++++++++++++++++++++++ 9 files changed, 177 insertions(+), 52 deletions(-) create mode 100644 .rspec delete mode 100644 features/kiss.feature delete mode 100644 features/step_definitions/kiss_steps.rb delete mode 100644 features/support/env.rb create mode 100644 spec/kiss/app_info_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore index 9e9d7da..ccef4e1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ html Gemfile.lock .idea/ *.gem +/public/ diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..c99d2e7 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/Rakefile b/Rakefile index 22e020a..e1dc94f 100644 --- a/Rakefile +++ b/Rakefile @@ -24,20 +24,20 @@ def dump_load_path end end -gem 'json', '~> 1.8.3' - -gem 'bundler', '~> 1.7' +# gem 'json', '~> 1.8.3' +# +# gem 'bundler', '~> 1.7' require 'bundler' -gem 'rake', '~> 11.3.0' +# gem 'rake', '~> 11.3.0' require 'rake/clean' require 'rake/testtask' -require 'cucumber' -require 'cucumber/rake/task' -gem 'rdoc' # we need the installed RDoc gem, not the system one -require 'rdoc/task' +# require 'cucumber' +# require 'cucumber/rake/task' +# gem 'rdoc' # we need the installed RDoc gem, not the system one +# require 'rdoc/task' include Rake::DSL @@ -49,19 +49,18 @@ Rake::TestTask.new do |t| end -CUKE_RESULTS = 'results.html' -CLEAN << CUKE_RESULTS -Cucumber::Rake::Task.new(:features) do |t| - t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x" - t.fork = false -end - -Rake::RDocTask.new do |rd| - - rd.main = "README.rdoc" - - rd.rdoc_files.include("README.rdoc", "lib/**/*.rb", "bin/**/*") -end - -task :default => [:test, :features] - +# CUKE_RESULTS = 'results.html' +# CLEAN << CUKE_RESULTS +# Cucumber::Rake::Task.new(:features) do |t| +# t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x" +# t.fork = false +# end + +# Rake::RDocTask.new do |rd| +# +# rd.main = "README.rdoc" +# +# rd.rdoc_files.include("README.rdoc", "lib/**/*.rb", "bin/**/*") +# end +# +# task :default => [:test, :features] diff --git a/features/kiss.feature b/features/kiss.feature deleted file mode 100644 index 8b2b7cc..0000000 --- a/features/kiss.feature +++ /dev/null @@ -1,6 +0,0 @@ -Feature: My bootstrapped app kinda works - In order to get going on coding my awesome app - I want to have aruba and cucumber setup - So I don't have to do it myself - - Scenario: App just runs diff --git a/features/step_definitions/kiss_steps.rb b/features/step_definitions/kiss_steps.rb deleted file mode 100644 index 5fe9e7a..0000000 --- a/features/step_definitions/kiss_steps.rb +++ /dev/null @@ -1 +0,0 @@ -# Put your step definitions here diff --git a/features/support/env.rb b/features/support/env.rb deleted file mode 100644 index 9b4b914..0000000 --- a/features/support/env.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'aruba/cucumber' - -ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}" -LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', 'lib') - -Before do - # Using "announce" causes massive warnings on 1.9.2 - @puts = true - @original_rubylib = ENV['RUBYLIB'] - ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s -end - -After do - ENV['RUBYLIB'] = @original_rubylib -end diff --git a/kiss-tnc.gemspec b/kiss-tnc.gemspec index 72a6642..f91442b 100644 --- a/kiss-tnc.gemspec +++ b/kiss-tnc.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| spec.summary = %q{Library for KISS communication with TNCs.} spec.description = %q{Ruby library for KISS communication with Terminal Node Controllers.} - spec.homepage = 'https://github.com/Syncleus/aprs' + spec.homepage = 'https://git.qoto.org/digipex/kiss-tnc' # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' # to allow pushing to a single host or delete this section to allow pushing to any host. @@ -29,10 +29,12 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_dependency 'abstraction', '~> 0.0.4' + spec.add_dependency 'abstractify', '~> 1.0' spec.add_dependency 'serialport', '~> 1.3' - spec.add_development_dependency 'bundler', '~> 1.7' - spec.add_development_dependency 'rake', '~> 11.3' - spec.add_development_dependency 'rdoc', '~> 4.2' - spec.add_development_dependency 'aruba', '~> 0.14' + spec.add_development_dependency 'bundler', '~> 2.3' + spec.add_development_dependency 'rake', '~> 13.0' + spec.add_development_dependency 'rspec', '~> 3.12' + spec.add_development_dependency 'simplecov', '~> 0.22' + spec.add_development_dependency 'simplecov-console', '~> 0.9' + #spec.add_development_dependency 'rdoc', '~> 6.5' end diff --git a/spec/kiss/app_info_spec.rb b/spec/kiss/app_info_spec.rb new file mode 100644 index 0000000..4931074 --- /dev/null +++ b/spec/kiss/app_info_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../lib/kiss/app_info' + +describe Kiss do + describe "::VERSION" do + context "After loading app_info" do + it "the VERSION variable is set" do + expect(Kiss::VERSION).to_not be_nil + expect(Kiss::VERSION.length > 0).to be_truthy + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..c6ebbb0 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,132 @@ +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +require 'simplecov' +require 'simplecov-console' + +SimpleCov.start do + add_filter '/test/' + add_filter '/spec/' + add_filter '/config/' + add_filter '/vendor/' + + add_group 'Plugins', 'lib/digipex/plugins' + add_group 'Routing', 'lib/digipex/routing' + + #coverage_criterion :branch + enable_coverage :branch + track_files '{app,lib}/**/*.rb' +end +# OPTIONAL +# This outputs the report to your public folder +# You will want to add this to .gitignore +SimpleCov.coverage_dir 'public/coverage' + +SimpleCov::Formatter::Console.sort = 'path' # sort by file path +SimpleCov::Formatter::Console.show_covered = true # show all files in coverage report +SimpleCov::Formatter::Console.max_rows = 300 # integer +#SimpleCov::Formatter::Console.max_lines = 5 # integer +SimpleCov::Formatter::Console.missing_len = 15 # integer +#SimpleCov::Formatter::Console.output_style = 'block' # 'table' (default) or 'block' +#SimpleCov::Formatter::Console.table_options = {:style => {:width => 200}} + +SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::Console, +]) + +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +#=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + #config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + #config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + #config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + #if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + #end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 2 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + #config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + #Kernel.srand config.seed +#=end +end -- GitLab