diff --git a/.rspec b/.rspec index 7e703cb..67e4680 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1,2 @@ ---format documentation --color ---backtrace +--require spec_helper \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d31aa5f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +# Next Release + +* Enhancements +* Bug Fixes +* Deprecations +* Incompatible Changes diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..0c723c4 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,122 @@ +# Contributing + +## Forking + +[Fork this repository](https://github.com/rapid7/metasploit-erd/fork) + +## Branching + +Branch names follow the format `TYPE/ISSUE/SUMMARY`. You can create it with `git checkout -b TYPE/ISSUE/SUMMARY`. + +### `TYPE` + +`TYPE` can be `bug`, `chore`, or `feature`. + +### `ISSUE` + +`ISSUE` is either a [Github issue](https://github.com/rapid7/metasploit-erd/issues) or an issue from some other +issue tracking software. + +### `SUMMARY` + +`SUMMARY` is is short summary of the purpose of the branch composed of lower case words separated by '-' so that it is a valid `PRERELEASE` for the Gem version. + +## Changes + +### `PRERELEASE` + +1. Update `PRERELEASE` to match the `SUMMARY` in the branch name. If you branched from `master`, and [version.rb](lib/metasploit/erd/version.rb) does not have `PRERELEASE` defined, then adding the following lines after `PATCH`: +``` +# The prerelease version, scoped to the {MAJOR}, {MINOR}, and {PATCH} version number. +PRERELEASE = '' +``` +2. `rake spec` +3. Verify the specs pass, which indicates that `PRERELEASE` was updated correctly. +4. Commit the change `git commit -a` + +### Your changes + +Make your changes or however many commits you like, committing each with `git commit`. + +### Pre-Pull Request Testing + +1. Run specs one last time before opening the Pull Request: `rake spec` +2. Verify there was no failures. + +### Push + +Push your branch to your fork on gitub: `git push TYPE/ISSUE/SUMMARY` + +### Pull Request + +* [Create new Pull Request](https://github.com/rapid7/metasploit-erd/compare/) +* Add a Verification Steps to the description comment + +``` +# Verification Steps + +- [ ] `bundle install` + +## `rake spec` +- [ ] `rake spec` +- [ ] VERIFY no failures +``` + +You should also include at least one scenario to manually check the changes outside of specs. + +* Add a Post-merge Steps comment + +The 'Post-merge Steps' are a reminder to the reviewer of the Pull Request of how to update the [`PRERELEASE`](lib/metasploit/erd/version.rb) so that [version_spec.rb](spec/lib/metasploit/erd/version.rb_spec.rb) passes on the target branch after the merge. + +DESTINATION is the name of the destination branch into which the merge is being made. SOURCE_SUMMARY is the SUMMARY from TYPE/ISSUE/SUMMARY branch name for the SOURCE branch that is being made. + +When merging to `master`: + +``` +# Post-merge Steps + +Perform these steps prior to pushing to master or the build will be broke on master. + +## Version +- [ ] Edit `lib/metasploit/erd/version.rb` +- [ ] Remove `PRERELEASE` and its comment as `PRERELEASE` is not defined on master. + +## Gem build +- [ ] gem build *.gemspec +- [ ] VERIFY the gem has no '.pre' version suffix. + +## RSpec +- [ ] `rake spec` +- [ ] VERIFY version examples pass without failures + +## Commit & Push +- [ ] `git commit -a` +- [ ] `git push origin master` +``` + +When merging to DESTINATION other than `master`: + +``` +# Post-merge Steps + +Perform these steps prior to pushing to DESTINATION or the build will be broke on DESTINATION. + +## Version +- [ ] Edit `lib/metasploit/erd/version.rb` +- [ ] Change `PRERELEASE` from `SOURCE_SUMMARY` to `DESTINATION_SUMMARY` to match the branch (DESTINATION) summary (DESTINATION_SUMMARY) + +## Gem build +- [ ] gem build metasploit-erd.gemspec +- [ ] VERIFY the prerelease suffix has change on the gem. + +## RSpec +- [ ] `rake spec` +- [ ] VERIFY version examples pass without failures + +## Commit & Push +- [ ] `git commit -a` +- [ ] `git push origin DESTINATION` +``` + +To update the [CHANGELOG.md](CHANGELOG.md) with the merged changes or release the merged code see +[RELEASING.md](RELEASING.md) diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..49b9b5c --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,80 @@ +# Releasing + +These steps can be added to the Pull Request description's task list to remind the reviewer of how to release the +gem. + +``` +# Release + +Complete these steps on DESTINATION + +## [CHANGELOG.md](CHANGELOG.md) + +### Terminology + +* "Enhancements" are widdening the API, such as by adding new classes or methods. +* "Bug Fixes" are fixes to the implementation that do not affect the public API. If the public API is affected then + the change should be listed as both a "Bug Fix" and either an "Enhancement" or "Incompatible Change" depending on how + the bug was fixed. +* "Deprecations" are changes to the implementation that cause deprecation warnings to be issued for APIs which will be + removed in a future major release. "Deprecations" are usually accompanied by an Enhancement that creates a new API + that is meant to be used in favor of the deprecated API. +* "Incompatbile Changes" are the removal of classes or methods or new required arguments or setup that shrink the API. + It is best practice to make a "Deprecation" for the API prior to its removal. + +### Task List + +- [ ] Generate the list of changes since the last release: `git log v....HEAD` +- [ ] For each commit in the release, find the corresponding PR by search for the commit on Github. +- [ ] For each PR, determine whether it is an Enhancement, Bug Fix, Deprecation, and/or Incompatible Change. A PR can + be in more than one category, in which case it should be listed in each category it belongs, but with a category + specific description of the change. +- [ ] Add an item to each category's list in the following format: `[#](https://github.com/rapid7/metasploit-erd/pull/) - [@](https://github.com/)` + `consumer_summary` should be a summary of the Enhancement, Bug Fix, Deprecation, or Incompatible Change from a + downstream consumer's of the library's perspective. `github_user` should be Github handle of the author of the + PR. +- [ ] If you added any Deprecations or Incompatible Changes, then adding upgrading information to + [UPGRADING.md](UPGRADING.md) + +## `VERSION` + +The entries in the [CHANGELOG.md](CHANGELOG.md) can be used to help determine how the `VERSION` should be bumped. + +### Compatible changes + +If the [CHANGELOG.md](CHANGELOG.md) contains only Enhancements, Bug Fixes, and/or Deprecations for the Next Release then +increment [`PATCH`](lib/metasploit/erd/version.rb). + +### Incompatible changes + +If the [CHANGELOG.md](CHANGELOG.md) contains any Incompatible Changes for the Next Release, then you can either (1) +decide to remain pre-1.0.0 or (2) advance to 1.0.0. + +1. To remain pre-1..0.0, then increment [`MINOR`](lib/metasploit/erd/version.rb) and reset [`PATCH`](lib/metasploit/erd/version.rb) to `0`. +2. To advance to 1.0.0, increment [`MAJOR`](lib/metasploit/erd/version.rb) and reset [`MINOR`](lib/metasploit/erd/version.rb and [`PATCH`](lib/metasploit/erd/version.rb) to `0`. + +## Setup [CHANGELOG.md](CHANGELOG.md) for next release + +- [ ] Change `Next Release` section name at the top of [CHANGELOG.md](CHANGELOG.md) to match the current `VERSION`. +- [ ] Add a new `Next Release` section above the `VERSION`'s section you just renamed: +
+# Next Release
+
+* Enhancements
+* Bug Fixes
+* Deprecations
+* Incompatible Changes
+
+ +## Release to rubygems.org + +## ruby-2.1 +- [ ] `rvm use ruby-2.1@metasploit-erd` +- [ ] `rm Gemfile.lock` +- [ ] `bundle install` +- [ ] `rake release` +``` + +### Downstream dependencies + +There are currently no known downstream dependencies diff --git a/Rakefile b/Rakefile index 60cefa4..d534bfc 100644 --- a/Rakefile +++ b/Rakefile @@ -1,9 +1,7 @@ -require "bundler/gem_tasks" -require "rspec/core/rake_task" - -require 'yard' -load 'tasks/yard.rake' +require 'bundler/gem_tasks' +require 'bundler/setup' +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -task :default => :spec +task default: :spec diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 0000000..ed67e4c --- /dev/null +++ b/UPGRADING.md @@ -0,0 +1 @@ +No Deprecations or Incompatible Changes have been introduced at this time \ No newline at end of file diff --git a/lib/metasploit/erd/cluster.rb b/lib/metasploit/erd/cluster.rb index 6787778..d51d129 100644 --- a/lib/metasploit/erd/cluster.rb +++ b/lib/metasploit/erd/cluster.rb @@ -21,9 +21,9 @@ def class_set class_entity = Metasploit::ERD::Entity::Class.new(klass) - class_entity.class_set.each do |klass| - unless visited_class_set.include? klass - class_queue << klass + class_entity.class_set.each do |set_class| + unless visited_class_set.include? set_class + class_queue << set_class end end diff --git a/lib/metasploit/erd/diagram.rb b/lib/metasploit/erd/diagram.rb index a9a44cc..2ec2ce2 100644 --- a/lib/metasploit/erd/diagram.rb +++ b/lib/metasploit/erd/diagram.rb @@ -59,7 +59,7 @@ class Metasploit::ERD::Diagram < RailsERD::Diagram::Graphviz parent.mkpath end - instance_eval &supersave + instance_eval(&supersave) } # diff --git a/lib/metasploit/erd/version.rb b/lib/metasploit/erd/version.rb index ba33d3f..8caabf7 100644 --- a/lib/metasploit/erd/version.rb +++ b/lib/metasploit/erd/version.rb @@ -2,18 +2,31 @@ module Metasploit module ERD # Holds components of {VERSION} as defined by {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0}. module Version + # + # CONSTANTS + # + # The major version number. MAJOR = 0 # The minor version number, scoped to the {MAJOR} version number. MINOR = 0 - # The patch number, scoped to the {MINOR} version number. - PATCH = 1 + # The patch version number, scoped to the {MAJOR} and {MINOR} version numbers. + PATCH = 3 + # The prerelease version, scoped to the {MAJOR}, {MINOR}, and {PATCH} version numbers. + PRERELEASE = 'metasploit-version' + + # + # Module Methods + # - # The full version string, including the {MAJOR}, {MINOR}, {PATCH}, and optionally, the `PRERELEASE` in the + # The full version string, including the {Metasploit::ERD::Version::MAJOR}, + # {Metasploit::ERD::Version::MINOR}, {Metasploit::ERD::Version::PATCH}, and optionally, the + # `Metasploit::ERD::Version::PRERELEASE` in the # {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0} format. # - # @return [String] '{MAJOR}.{MINOR}.{PATCH}' on master. '{MAJOR}.{MINOR}.{PATCH}-``' on any branch - # other than master. + # @return [String] '{Metasploit::ERD::Version::MAJOR}.{Metasploit::ERD::Version::MINOR}.{Metasploit::ERD::Version::PATCH}' + # on master. '{Metasploit::ERD::Version::MAJOR}.{Metasploit::ERD::Version::MINOR}.{Metasploit::ERD::Version::PATCH}-PRERELEASE' + # on any branch other than master. def self.full version = "#{MAJOR}.#{MINOR}.#{PATCH}" @@ -24,20 +37,23 @@ def self.full version end - # The full gem version string, including the {MAJOR}, {MINOR}, {PATCH}, and optionally, the {PRERELEASE} in the + # The full gem version string, including the {Metasploit::ERD::Version::MAJOR}, + # {Metasploit::ERD::Version::MINOR}, {Metasploit::ERD::Version::PATCH}, and optionally, the + # `Metasploit::ERD::Version::PRERELEASE` in the # {http://guides.rubygems.org/specification-reference/#version RubyGems versioning} format. # - # @return [String] '{MAJOR}.{MINOR}.{PATCH}' on master. '{MAJOR}.{MINOR}.{PATCH}.{PRERELEASE}' on any branch - # other than master. + # @return [String] '{Metasploit::ERD::Version::MAJOR}.{Metasploit::ERD::Version::MINOR}.{Metasploit::ERD::Version::PATCH}' + # on master. '{Metasploit::ERD::Version::MAJOR}.{Metasploit::ERD::Version::MINOR}.{Metasploit::ERD::Version::PATCH}.PRERELEASE' + # on any branch other than master. def self.gem full.gsub('-', '.pre.') end end - # @see Version.gem + # (see Version.gem) GEM_VERSION = Version.gem - # @see Version.full + # (see Version.full) VERSION = Version.full end end diff --git a/metasploit-erd.gemspec b/metasploit-erd.gemspec index 0ec771d..d3ebdbe 100644 --- a/metasploit-erd.gemspec +++ b/metasploit-erd.gemspec @@ -22,8 +22,9 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.1' spec.add_development_dependency 'bundler', '~> 1.5' + spec.add_development_dependency 'metasploit-version', '~> 0.1.3' spec.add_development_dependency 'rake', '~> 10.3' - spec.add_development_dependency 'rspec', '~> 2.14' + spec.add_development_dependency 'rspec', '~> 3.2' # restrict from rails 4.0 to be compatible with rest of metasploit ecosystem. # @todo Update to work with rails 4 (MSP-9836) diff --git a/spec/lib/metasploit/erd/version_spec.rb b/spec/lib/metasploit/erd/version_spec.rb new file mode 100644 index 0000000..3cb4714 --- /dev/null +++ b/spec/lib/metasploit/erd/version_spec.rb @@ -0,0 +1,3 @@ +RSpec.describe Metasploit::ERD::Version do + it_should_behave_like 'Metasploit::Version Version Module' +end diff --git a/spec/lib/metasploit/erd_spec.rb b/spec/lib/metasploit/erd_spec.rb new file mode 100644 index 0000000..74a57b7 --- /dev/null +++ b/spec/lib/metasploit/erd_spec.rb @@ -0,0 +1,4 @@ +RSpec.describe Metasploit::ERD do + it_should_behave_like 'Metasploit::Version GEM_VERSION constant' + it_should_behave_like 'Metasploit::Version VERSION constant' +end diff --git a/spec/metasploit/erd/cluster_spec.rb b/spec/metasploit/erd/cluster_spec.rb index 1315f8f..733846a 100644 --- a/spec/metasploit/erd/cluster_spec.rb +++ b/spec/metasploit/erd/cluster_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::ERD::Cluster do +RSpec.describe Metasploit::ERD::Cluster do include_context 'ActiveRecord::Base connection' include_context 'ActiveRecord::Base.descendants cleaner' @@ -151,8 +149,8 @@ [] end - it { should be_a Set } - it { should be_empty } + it { is_expected.to be_a Set } + it { is_expected.to be_empty } end end end \ No newline at end of file diff --git a/spec/metasploit/erd/diagram_spec.rb b/spec/metasploit/erd/diagram_spec.rb index dd893df..b291c29 100644 --- a/spec/metasploit/erd/diagram_spec.rb +++ b/spec/metasploit/erd/diagram_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::ERD::Diagram do +RSpec.describe Metasploit::ERD::Diagram do subject(:diagram) { described_class.new(*arguments) } @@ -15,7 +13,7 @@ RailsERD::Domain.new } - it { should be_a RailsERD::Diagram::Graphviz } + it { is_expected.to be_a RailsERD::Diagram::Graphviz } context 'CONSTANTS' do context 'ATTRIBUTES' do @@ -23,10 +21,10 @@ described_class::ATTRIBUTES } - it { should include :content } - it { should include :foreign_keys } - it { should include :primary_keys } - it { should include :timestamps } + it { is_expected.to include :content } + it { is_expected.to include :foreign_keys } + it { is_expected.to include :primary_keys } + it { is_expected.to include :timestamps } end context 'DEFAULT_OPTIONS' do @@ -100,7 +98,7 @@ described_class::FILETYPE } - it { should == :png } + it { is_expected.to eq(:png) } end context 'INDIRECT' do @@ -108,7 +106,7 @@ described_class::INDIRECT } - it { should be_false } + it { is_expected.to eq(false) } end context 'INHERITANCE' do @@ -116,7 +114,7 @@ described_class::INHERITANCE } - it { should be_true } + it { is_expected.to eq(true) } end context 'NOTATION' do @@ -124,7 +122,7 @@ described_class::NOTATION } - it { should == :crowsfoot } + it { is_expected.to eq(:crowsfoot) } end context 'POLYMORPHISM' do @@ -132,7 +130,7 @@ described_class::POLYMORPHISM } - it { should be_true } + it { is_expected.to eq(true) } end end @@ -146,7 +144,7 @@ callbacks[:each_entity] } - it { should_not be_nil } + it { is_expected.to_not be_nil } it 'uses RailsERD::Diagram::Graphviz.callbacks[:each_entity]' do expect(each_entity).to eq(RailsERD::Diagram::Graphviz.send(:callbacks)[:each_entity]) @@ -158,7 +156,7 @@ callbacks[:each_relationship] } - it { should_not be_nil } + it { is_expected.to_not be_nil } it 'uses RailsERD::Diagram::Graphviz.callbacks[:each_relationship]' do expect(each_relationship).to eq(RailsERD::Diagram::Graphviz.send(:callbacks)[:each_relationship]) @@ -170,7 +168,7 @@ callbacks[:each_specialization] } - it { should_not be_nil } + it { is_expected.to_not be_nil } it 'uses RailsERD::Diagram::Graphviz.callbacks[:each_specialization]' do expect(each_specialization).to eq(RailsERD::Diagram::Graphviz.send(:callbacks)[:each_specialization]) @@ -182,7 +180,7 @@ callbacks[:save] } - it { should_not be_nil } + it { is_expected.to_not be_nil } it 'extends RailsERD::Diagram::Graphviz.callbacks[:save]' do expect(save).not_to eq(RailsERD::Diagram::Graphviz.send(:callbacks)[:save]) @@ -194,7 +192,7 @@ callbacks[:setup] } - it { should_not be_nil } + it { is_expected.to_not be_nil } it 'uses RailsERD::Diagram::Graphviz.callbacks[:setup]' do expect(setup).to eq(RailsERD::Diagram::Graphviz.send(:callbacks)[:setup]) diff --git a/spec/metasploit/erd/entity/class_spec.rb b/spec/metasploit/erd/entity/class_spec.rb index 984c2dc..481451c 100644 --- a/spec/metasploit/erd/entity/class_spec.rb +++ b/spec/metasploit/erd/entity/class_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::ERD::Entity::Class do +RSpec.describe Metasploit::ERD::Entity::Class do include_context 'ActiveRecord::Base.descendants cleaner' subject(:class_entity) { @@ -116,7 +114,7 @@ end it 'includes class once' do - expect(class_set).to have(1).items + expect(class_set.length).to eq(1) expect(class_set).to include(target) end end @@ -208,7 +206,7 @@ end it 'includes belongs_to target classes' do - expect(class_set).to include(belongs_to_target) + expect(class_set.map(&:name)).to include(belongs_to_target.name) end it 'does not include has_many target classes' do @@ -218,7 +216,7 @@ end context 'without belongs_to associations' do - it { should be_empty } + it { is_expected.to be_empty } end end diff --git a/spec/metasploit/erd/entity/namespace_spec.rb b/spec/metasploit/erd/entity/namespace_spec.rb index acf1a1e..d420dc6 100644 --- a/spec/metasploit/erd/entity/namespace_spec.rb +++ b/spec/metasploit/erd/entity/namespace_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::ERD::Entity::Namespace do +RSpec.describe Metasploit::ERD::Entity::Namespace do include_context 'ActiveRecord::Base.descendants cleaner' subject(:namespace_entity) { @@ -107,7 +105,7 @@ end context 'without ActiveRecord::Base descendants' do - it { should be_empty } + it { is_expected.to be_empty } end end diff --git a/spec/metasploit/erd/relationship_spec.rb b/spec/metasploit/erd/relationship_spec.rb index 26d9a12..f051223 100644 --- a/spec/metasploit/erd/relationship_spec.rb +++ b/spec/metasploit/erd/relationship_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::ERD::Relationship do +RSpec.describe Metasploit::ERD::Relationship do include_context 'ActiveRecord::Base connection' include_context 'ActiveRecord::Base.descendants cleaner' @@ -75,7 +73,7 @@ end end - it { should be_a Set } + it { is_expected.to be_a Set } it 'includes association.klass' do expect(class_set).to include(association.klass) @@ -137,7 +135,7 @@ end end - it { should be_a Set } + it { is_expected.to be_a Set } it 'includes all classes that have has_many , as: ' do expect(class_set).to eq(Set.new(things)) @@ -225,7 +223,7 @@ end end - it { should be_a Set } + it { is_expected.to be_a Set } context 'with has_many as: ' do it 'includes classes' do diff --git a/spec/metasploit/erd/version_spec.rb b/spec/metasploit/erd/version_spec.rb deleted file mode 100644 index 42e309d..0000000 --- a/spec/metasploit/erd/version_spec.rb +++ /dev/null @@ -1,125 +0,0 @@ -require 'spec_helper' - -require 'active_support/core_ext/object/blank' - -describe Metasploit::ERD::Version do - context 'CONSTANTS' do - context 'MAJOR' do - subject(:major) do - described_class::MAJOR - end - - it 'is 0 because the API is not locked yet' do - expect(major).to eq(0) - end - end - - context 'MINOR' do - subject(:minor) do - described_class::MINOR - end - - it { should be_a Integer } - end - - context 'PATCH' do - subject(:patch) do - described_class::PATCH - end - - it { should be_a Integer } - end - - pull_request = ENV['TRAVIS_PULL_REQUEST'] - - # a pull request cannot check PRERELEASE because it will be tested in the target branch, but the source itself - # is from the source branch and so has the source branch PRERELEASE. - # - # PRERELEASE can only be set appropriately for a merge by merging to the target branch and then updating PRERELEASE - # on the target branch before committing and/or pushing to github and travis-ci. - if pull_request.nil? || pull_request == 'false' - context 'PREPRELEASE' do - subject(:prerelease) do - described_class::PRERELEASE - end - - branch = ENV['TRAVIS_BRANCH'] - - if branch.blank? - branch = `git rev-parse --abbrev-ref HEAD`.strip - end - - if branch == 'master' - it 'does not have a PRERELEASE' do - expect(defined? described_class::PRERELEASE).to be_nil - end - else - feature_regex = /(feature|staging)\/(?.*)/ - match = branch.match(feature_regex) - - if match - it 'matches the branch relative name' do - expect(prerelease).to eq(match[:prerelease]) - end - else - it 'has a abbreviated reference that can be parsed for prerelease' do - fail "Do not know how to parse #{branch.inspect} for PRERELEASE" - end - end - end - end - end - end - - context 'full' do - subject(:full) do - described_class.full - end - - # - # lets - # - - let(:major) do - 1 - end - - let(:minor) do - 2 - end - - let(:patch) do - 3 - end - - before(:each) do - stub_const("#{described_class}::MAJOR", major) - stub_const("#{described_class}::MINOR", minor) - stub_const("#{described_class}::PATCH", patch) - end - - context 'with PRERELEASE' do - let(:prerelease) do - 'prerelease' - end - - before(:each) do - stub_const("#{described_class}::PRERELEASE", prerelease) - end - - it 'is ..-' do - expect(full).to eq("#{major}.#{minor}.#{patch}-#{prerelease}") - end - end - - context 'without PRERELEASE' do - before(:each) do - hide_const("#{described_class}::PRERELEASE") - end - - it 'is ..' do - expect(full).to eq("#{major}.#{minor}.#{patch}") - end - end - end -end \ No newline at end of file diff --git a/spec/metasploit/erd_spec.rb b/spec/metasploit/erd_spec.rb deleted file mode 100644 index 9da938d..0000000 --- a/spec/metasploit/erd_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -describe Metasploit::ERD do - context 'CONSTANTS' do - context 'VERSION' do - subject(:version) do - described_class::VERSION - end - - it 'is Metasploit::ERD::Version.full' do - expect(version).to eq(Metasploit::ERD::Version.full) - end - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9c0a86a..883aab3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,4 @@ -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +require 'bundler/setup' # require before 'metasploit/erd' so coverage is shown for files required by 'metasploit/erd' require 'simplecov' @@ -14,13 +14,95 @@ ] end +# +# Gems +# + +require 'metasploit/version' + +# +# Project +# + require 'metasploit/erd' -# Requires supporting ruby files with custom matchers and macros, etc, -# in spec/support/ and its subdirectories. -spec_pathname = Pathname.new(__FILE__).realpath.parent -glob_pathname = spec_pathname.join('support', '**', '*.rb') +roots = [] +roots << Pathname.new(__FILE__).realpath.parent.parent.to_path + +# Use find_all_by_name instead of find_by_name as find_all_by_name will return pre-release versions +gem_specification = Gem::Specification.find_all_by_name('metasploit-version').first +roots << gem_specification.gem_dir + +roots.each do |root| + Dir[File.join(root, 'spec', 'support', '**', '*.rb')].each do |f| + require f + end +end + +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 + expectations.syntax = :expect + end + + config.expose_dsl_globally = false + + # These two settings work together to allow 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. + config.filter_run :focus + config.run_all_when_everything_filtered = 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 + + # 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| + mocks.syntax = :expect + mocks.patch_marshal_to_support_partial_doubles = false + # 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 + + # 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 + + # 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 = 10 -Dir[glob_pathname].each do |f| - require f + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true end diff --git a/spec/support/shared/contexts/active_record_base_connection.rb b/spec/support/shared/contexts/active_record_base_connection.rb index 3035e1d..0bd61d0 100644 --- a/spec/support/shared/contexts/active_record_base_connection.rb +++ b/spec/support/shared/contexts/active_record_base_connection.rb @@ -1,4 +1,4 @@ -shared_context 'ActiveRecord::Base connection' do +RSpec.shared_context 'ActiveRecord::Base connection' do before(:each) do ActiveRecord::Base.establish_connection( adapter: 'sqlite3', diff --git a/spec/support/shared/contexts/active_record_base_descendants_cleaner.rb b/spec/support/shared/contexts/active_record_base_descendants_cleaner.rb index 2903ecc..c066603 100644 --- a/spec/support/shared/contexts/active_record_base_descendants_cleaner.rb +++ b/spec/support/shared/contexts/active_record_base_descendants_cleaner.rb @@ -1,4 +1,4 @@ -shared_context 'ActiveRecord::Base.descendants cleaner' do +RSpec.shared_context 'ActiveRecord::Base.descendants cleaner' do before(:each) do expect(ActiveRecord::Base.direct_descendants).to be_empty end diff --git a/spec/support/shared/examples/metasploit/erd/clusterable.rb b/spec/support/shared/examples/metasploit/erd/clusterable.rb index 5282779..7804759 100644 --- a/spec/support/shared/examples/metasploit/erd/clusterable.rb +++ b/spec/support/shared/examples/metasploit/erd/clusterable.rb @@ -1,4 +1,4 @@ -shared_examples_for 'Metasploit::ERD::Clusterable' do +RSpec.shared_examples_for 'Metasploit::ERD::Clusterable' do include_context 'ActiveRecord::Base connection' # @@ -68,7 +68,7 @@ def self.table_name_prefix [] } - it { should be_a Metasploit::ERD::Diagram } + it { is_expected.to be_a Metasploit::ERD::Diagram } context 'Metasploit::ERD::Diagram#create' do subject(:create) { @@ -256,7 +256,7 @@ def self.table_name_prefix options[:title] } - it { should be_a String } + it { is_expected.to be_a String } end end end