diff --git a/.rspec b/.rspec old mode 100755 new mode 100644 index 8af0697f..83e16f80 --- a/.rspec +++ b/.rspec @@ -1,4 +1,2 @@ ---backtrace ---colour ---drb ---format documentation +--color +--require spec_helper diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..d31aa5fb --- /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 index 43976e34..27c67bcf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,19 +25,18 @@ issue tracking software. ### `PRERELEASE` -1. Update `PRERELEASE` to match the `SUMMARY` in the branch name. If you branched from `master`, and [version.rb](lib/metasploit/model/version.rb) does not have `PRERELEASE` defined, then adding the following lines after `PATCH`: +1. Update `PRERELEASE` to match the `SUMMARY` in the branch name. If you branched from `master`, and [version.rb](lib/metasploit/model/version.rb) does not have `PRERELEASE` defined, then adding the following lines after `PATCH`: ``` -# The prerelease version, scoped to the {PATCH} version number. +# 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, commiting each with `git commit`. +Make your changes or however many commits you like, committing each with `git commit`. ### Pre-Pull Request Testing @@ -46,12 +45,12 @@ Make your changes or however many commits you like, commiting each with `git com ### Push -Push your branch to your fork on gitub: `git push push TYPE/ISSUE/SUMMARY` +Push your branch to your fork on github: `git push TYPE/ISSUE/SUMMARY` ### Pull Request * [Create new Pull Request](https://github.com/rapid7/metasploit-model/compare/) -* Add a Verification Steps comment +* Add a Verification Steps to the description comment ``` # Verification Steps @@ -62,6 +61,7 @@ Push your branch to your fork on gitub: `git push push TYPE/ISSUE/SUMMARY` - [ ] `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 @@ -106,7 +106,7 @@ Perform these steps prior to pushing to DESTINATION or the build will be broke o - [ ] Change `PRERELEASE` from `SOURCE_SUMMARY` to `DESTINATION_SUMMARY` to match the branch (DESTINATION) summary (DESTINATION_SUMMARY) ## Gem build -- [ ] gem build *.gemspec +- [ ] gem build metasploit-model.gemspec - [ ] VERIFY the prerelease suffix has change on the gem. ## RSpec @@ -118,45 +118,5 @@ Perform these steps prior to pushing to DESTINATION or the build will be broke o - [ ] `git push origin DESTINATION` ``` -* Add a 'Release Steps' comment - -The 'Release Steps' are a reminder to the reviewer of the Pull Request of how to release the gem. - -``` -# Release - -Complete these steps on DESTINATION - -## Version - -### Compatible changes - -If the change are compatible with the previous branch's API, then increment [`PATCH`](lib/metasploit/model/version.rb). - -### Incompatible changes - -If your changes are incompatible with the previous branch's API, then increment -[`MINOR`](lib/metasploit/model/version.rb) and reset [`PATCH`](lib/metasploit/model/version.rb) to `0`. - -- [ ] Following the rules for [semantic versioning 2.0](http://semver.org/spec/v2.0.0.html), update -[`MINOR`](lib/metasploit/model/version.rb) and [`PATCH`](lib/metasploit/model/version.rb) and commit the changes. - -## JRuby -- [ ] `rvm use jruby@metasploit-model` -- [ ] `rm Gemfile.lock` -- [ ] `bundle install` -- [ ] `rake release` - -## MRI Ruby -- [ ] `rvm use ruby-2.1@metasploit-model` -- [ ] `rm Gemfile.lock` -- [ ] `bundle install` -- [ ] `rake release` -``` - -### Downstream dependencies - -When releasing new versions, the following projects may need to be updated: - -* [metasploit_data_models](https://github.com/rapid7/metasploit_data_models) -* [metasploit-credential](https://github.com/rapid7/metasploit-credential) +To update the [CHANGELOG.md](CHANGELOG.md) with the merged changes or release the merged code see +[RELEASING.md](RELEASING.md) diff --git a/Gemfile b/Gemfile index c36a9a66..6ed10ada 100644 --- a/Gemfile +++ b/Gemfile @@ -16,8 +16,8 @@ group :test do # rails is not used because activerecord should not be included, but rails would normally coordinate the versions # between its dependencies, which is now handled by this constraint. rails_version_constraint = [ - '>= 3.2.0', - '< 4.0.0' + '>= 4.0.9', + '< 4.1.0' ] # Dummy app uses actionpack for ActionController, but not rails since it doesn't use activerecord. @@ -26,9 +26,9 @@ group :test do gem 'coveralls', require: false # Engine tasks are loaded using railtie gem 'railties', *rails_version_constraint - gem 'rspec' + gem 'rspec', '~> 3.1' # need rspec-core >= 2.14.0 because 2.14.0 introduced RSpec::Core::SharedExampleGroup::TopLevel - gem 'rspec-core', '>= 2.14.0', '< 3.0.0' + gem 'rspec-core', '>= 2.14.0' # need rspec-rails >= 2.12.0 as 2.12.0 adds support for redefining named subject in nested context that uses the # named subject from the outer context without causing a stack overflow. gem 'rspec-rails', '>= 2.12.0' diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 00000000..d7e5093a --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,89 @@ +# 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-model/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. + +### Bug fixes + +If the [CHANGELOG.md](CHANGELOG.md) contains only Bug Fixes for the Next Release, then increment +[`PATCH`](lib/metasploit/model/version.rb). + +### Compatible API changes + +If the [CHANGELOG.md](CHANGELOG.md) contains any Enhancements or Deprecations, then increment +[`MINOR`](lib/metasploit/model/version.rb) and reset [`PATCH`](lib/metasploit/model/version.rb) to `0`. + +### Incompatible API changes + +If the [CHANGELOG.md](CHANGELOG.md) contains any Incompatible Change, then increment +[`MAJOR`](lib/metasploit/model/version.rb) and reset [`MINOR`](lib/metasploit/model/version.rb and +[`PATCH`](lib/metasploit/model/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 + +## jruby +- [ ] `rvm use jruby@metasploit-model` +- [ ] `rm Gemfile.lock` +- [ ] `bundle install` +- [ ] `rake release` + +## ruby-2.1 +- [ ] `rvm use ruby-2.1@metasploit-model` +- [ ] `rm Gemfile.lock` +- [ ] `bundle install` +- [ ] `rake release` +``` + +### Downstream dependencies + +There are currently no known downstream dependencies diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 00000000..ed67e4c7 --- /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/model.rb b/lib/metasploit/model.rb index a9168b8c..6c87c4e2 100644 --- a/lib/metasploit/model.rb +++ b/lib/metasploit/model.rb @@ -1,6 +1,11 @@ # # Gems # +# gems must load explicitly any gem declared in gemspec +# @see https://github.com/bundler/bundler/issues/2018#issuecomment-6819359 +# +# + require 'active_model' require 'active_support' diff --git a/lib/metasploit/model/engine.rb b/lib/metasploit/model/engine.rb index e0ca03e0..3e45ae62 100644 --- a/lib/metasploit/model/engine.rb +++ b/lib/metasploit/model/engine.rb @@ -14,7 +14,7 @@ class Metasploit::Model::Engine < Rails::Engine # Remove ActiveSupport::Dependencies loading paths to save time during constant resolution and to ensure that # metasploit-model is properly declaring all autoloads and not falling back on ActiveSupport::Dependencies - config.paths.each_value do |path| + config.paths.values.each do |path| path.skip_autoload! path.skip_autoload_once! path.skip_eager_load! diff --git a/lib/metasploit/model/version.rb b/lib/metasploit/model/version.rb index b92df99a..3531e47a 100644 --- a/lib/metasploit/model/version.rb +++ b/lib/metasploit/model/version.rb @@ -2,18 +2,31 @@ module Metasploit module Model # 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 + MAJOR = 1 # The minor version number, scoped to the {MAJOR} version number. - MINOR = 30 - # The patch number, scoped to the {MAJOR} and {MINOR} version numbers. + MINOR = 0 + # The patch version number, scoped to the {MAJOR} and {MINOR} version numbers. PATCH = 0 + # The prerelease version, scoped to the {MAJOR}, {MINOR}, and {PATCH} version numbers. + PRERELEASE = '1-0-0-plus' + + # + # Module Methods + # - # The full version string, including the {MAJOR}, {MINOR}, {PATCH}, and optionally, the {PRERELEASE} in the + # The full version string, including the {Metasploit::Model::Version::MAJOR}, + # {Metasploit::Model::Version::MINOR}, {Metasploit::Model::Version::PATCH}, and optionally, the + # `Metasploit::Model::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}-{PRERELEASE}' on any branch - # other than master. + # @return [String] '{Metasploit::Model::Version::MAJOR}.{Metasploit::Model::Version::MINOR}.{Metasploit::Model::Version::PATCH}' + # on master. '{Metasploit::Model::Version::MAJOR}.{Metasploit::Model::Version::MINOR}.{Metasploit::Model::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::Model::Version::MAJOR}, + # {Metasploit::Model::Version::MINOR}, {Metasploit::Model::Version::PATCH}, and optionally, the + # `Metasploit::Model::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::Model::Version::MAJOR}.{Metasploit::Model::Version::MINOR}.{Metasploit::Model::Version::PATCH}' + # on master. '{Metasploit::Model::Version::MAJOR}.{Metasploit::Model::Version::MINOR}.{Metasploit::Model::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-model.gemspec b/metasploit-model.gemspec index 47b11aa0..31b44c38 100644 --- a/metasploit-model.gemspec +++ b/metasploit-model.gemspec @@ -19,6 +19,7 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.1' spec.add_development_dependency 'bundler', '~> 1.3' + spec.add_development_dependency 'metasploit-version', '~> 0.1.3' spec.add_development_dependency 'metasploit-yard', '~> 1.0' spec.add_development_dependency 'rake' @@ -27,8 +28,12 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'yard', '< 0.8.7.4' # Dependency loading - spec.add_runtime_dependency 'activesupport' - spec.add_runtime_dependency 'railties', '< 4.0.0' + rails_version_constraints = ['>= 4.0.9', '< 4.1.0'] + + spec.add_runtime_dependency 'activemodel', *rails_version_constraints + spec.add_runtime_dependency 'activesupport', *rails_version_constraints + + spec.add_runtime_dependency 'railties', *rails_version_constraints if RUBY_PLATFORM =~ /java/ # markdown formatting for yard diff --git a/spec/app/models/metasploit/model/association/reflection_spec.rb b/spec/app/models/metasploit/model/association/reflection_spec.rb index 4a538656..5946f306 100644 --- a/spec/app/models/metasploit/model/association/reflection_spec.rb +++ b/spec/app/models/metasploit/model/association/reflection_spec.rb @@ -1,10 +1,8 @@ -require 'spec_helper' - -describe Metasploit::Model::Association::Reflection do +RSpec.describe Metasploit::Model::Association::Reflection, type: :model do context 'validations' do - it { should validate_presence_of :model } - it { should validate_presence_of :name } - it { should validate_presence_of :class_name } + it { is_expected.to validate_presence_of :model } + it { is_expected.to validate_presence_of :name } + it { is_expected.to validate_presence_of :class_name } end context '#klass' do @@ -42,7 +40,7 @@ end it 'should return Class with Class#name #class_name' do - klass.should == class_name_class + expect(klass).to eq(class_name_class) end end end \ No newline at end of file diff --git a/spec/app/models/metasploit/model/search/group/base_spec.rb b/spec/app/models/metasploit/model/search/group/base_spec.rb index ff2233b6..6ddaec9e 100644 --- a/spec/app/models/metasploit/model/search/group/base_spec.rb +++ b/spec/app/models/metasploit/model/search/group/base_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Group::Base do - it { should ensure_length_of(:children).is_at_least(1) } +RSpec.describe Metasploit::Model::Search::Group::Base, type: :model do + it { is_expected.to ensure_length_of(:children).is_at_least(1) } end \ No newline at end of file diff --git a/spec/app/models/metasploit/model/search/group/intersection_spec.rb b/spec/app/models/metasploit/model/search/group/intersection_spec.rb index a9262741..25bfb366 100644 --- a/spec/app/models/metasploit/model/search/group/intersection_spec.rb +++ b/spec/app/models/metasploit/model/search/group/intersection_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Group::Intersection do - it { should be_a Metasploit::Model::Search::Group::Base } +RSpec.describe Metasploit::Model::Search::Group::Intersection, type: :model do + it { is_expected.to be_a Metasploit::Model::Search::Group::Base } end \ No newline at end of file diff --git a/spec/app/models/metasploit/model/search/group/union_spec.rb b/spec/app/models/metasploit/model/search/group/union_spec.rb index 7612b4e4..9d1535f9 100644 --- a/spec/app/models/metasploit/model/search/group/union_spec.rb +++ b/spec/app/models/metasploit/model/search/group/union_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Group::Union do - it { should be_a Metasploit::Model::Search::Group::Base } +RSpec.describe Metasploit::Model::Search::Group::Union, type: :model do + it { is_expected.to be_a Metasploit::Model::Search::Group::Base } end \ No newline at end of file diff --git a/spec/app/models/metasploit/model/search/operation/association_spec.rb b/spec/app/models/metasploit/model/search/operation/association_spec.rb index 0be3222c..5c074fed 100644 --- a/spec/app/models/metasploit/model/search/operation/association_spec.rb +++ b/spec/app/models/metasploit/model/search/operation/association_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Association do +RSpec.describe Metasploit::Model::Search::Operation::Association, type: :model do subject(:operation) { described_class.new( source_operation: source_operation @@ -35,7 +33,7 @@ true } - it { should_not include(invalid_error) } + it { is_expected.not_to include(invalid_error) } end context 'without valid' do @@ -43,7 +41,7 @@ false } - it { should include(invalid_error) } + it { is_expected.to include(invalid_error) } end end @@ -56,12 +54,12 @@ nil } - it { should include(blank_error) } - it { should_not include(invalid_error) } + it { is_expected.to include(blank_error) } + it { is_expected.not_to include(invalid_error) } end end end - it { should_not respond_to :value } - it { should_not respond_to :value= } + it { is_expected.not_to respond_to :value } + it { is_expected.not_to respond_to :value= } end \ No newline at end of file diff --git a/spec/app/models/metasploit/model/search/operation/base_spec.rb b/spec/app/models/metasploit/model/search/operation/base_spec.rb index cb4ec75f..e492d017 100644 --- a/spec/app/models/metasploit/model/search/operation/base_spec.rb +++ b/spec/app/models/metasploit/model/search/operation/base_spec.rb @@ -1,13 +1,11 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Base do +RSpec.describe Metasploit::Model::Search::Operation::Base, type: :model do subject(:operation) do described_class.new end context 'validations' do context 'operator' do - it { should validate_presence_of(:operator) } + it { is_expected.to validate_presence_of(:operator) } context 'valid' do let(:errors) do @@ -40,7 +38,7 @@ end it 'should not record error on operator' do - errors.should_not include(error) + expect(errors).not_to include(error) end end @@ -50,7 +48,7 @@ end it 'should record error on operator' do - errors.should include(error) + expect(errors).to include(error) end end end @@ -61,7 +59,7 @@ end it 'should not record error on operator' do - errors.should_not include(error) + expect(errors).not_to include(error) end end end diff --git a/spec/app/models/metasploit/model/search/operation/boolean_spec.rb b/spec/app/models/metasploit/model/search/operation/boolean_spec.rb index 7b16c122..61cd42a2 100644 --- a/spec/app/models/metasploit/model/search/operation/boolean_spec.rb +++ b/spec/app/models/metasploit/model/search/operation/boolean_spec.rb @@ -1,21 +1,24 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Boolean do +RSpec.describe Metasploit::Model::Search::Operation::Boolean, type: :model do context 'CONSTANTS' do context 'FORMATTED_VALUE_TO_VALUE' do subject(:formatted_value_to_value) do described_class::FORMATTED_VALUE_TO_VALUE end - its(['false']) { should be_false } - its(['true']) { should be_true } + it "maps 'false' to false" do + expect(formatted_value_to_value['false']).to eq(false) + end + + it "maps 'true' to true" do + expect(formatted_value_to_value['true']).to eq(true) + end end end context 'validations' do - it { should allow_value(false).for(:value) } - it { should allow_value(true).for(:value) } - it { should_not allow_value(nil).for(:value) } + it { is_expected.to allow_value(false).for(:value) } + it { is_expected.to allow_value(true).for(:value) } + it { is_expected.not_to allow_value(nil).for(:value) } end context '#value' do @@ -32,7 +35,7 @@ 'false' end - it { should be_false } + it { is_expected.to eq(false) } end context "with 'true'" do @@ -40,7 +43,7 @@ 'true' end - it { should be_true } + it { is_expected.to eq(true) } end context 'with other' do @@ -49,7 +52,7 @@ end it 'should return value unparsed' do - value.should == formatted_value + expect(value).to eq(formatted_value) end end end diff --git a/spec/app/models/metasploit/model/search/operation/date_spec.rb b/spec/app/models/metasploit/model/search/operation/date_spec.rb index 1ae1f092..63cb793c 100644 --- a/spec/app/models/metasploit/model/search/operation/date_spec.rb +++ b/spec/app/models/metasploit/model/search/operation/date_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Date do +RSpec.describe Metasploit::Model::Search::Operation::Date, type: :model do context 'validation' do context 'value' do before(:each) do @@ -25,7 +23,7 @@ end it 'should not record error' do - errors.should_not include(error) + expect(errors).not_to include(error) end end @@ -35,7 +33,7 @@ end it 'should record error' do - errors.should include(error) + expect(errors).to include(error) end end end @@ -56,7 +54,7 @@ end it 'should be passed in Date' do - value.should == formatted_value + expect(value).to eq(formatted_value) end end @@ -71,7 +69,7 @@ end it 'should be parsed Date' do - value.should == date + expect(value).to eq(date) end end @@ -81,7 +79,7 @@ end it 'should pass through value' do - value.should be formatted_value + expect(value).to be formatted_value end end end diff --git a/spec/app/models/metasploit/model/search/operation/group/base_spec.rb b/spec/app/models/metasploit/model/search/operation/group/base_spec.rb index 235a9221..077c925b 100644 --- a/spec/app/models/metasploit/model/search/operation/group/base_spec.rb +++ b/spec/app/models/metasploit/model/search/operation/group/base_spec.rb @@ -1,15 +1,13 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Group::Base do +RSpec.describe Metasploit::Model::Search::Operation::Group::Base, type: :model do subject(:group) do described_class.new end - it { should be_a Metasploit::Model::Search::Operation::Base } + it { is_expected.to be_a Metasploit::Model::Search::Operation::Base } context 'validations' do context 'children' do - it { should ensure_length_of(:children).is_at_least(1).with_short_message('is too short (minimum is 1 child)') } + it { is_expected.to ensure_length_of(:children).is_at_least(1).with_short_message('is too short (minimum is 1 child)') } context '#children_valid' do subject(:children_valid) do @@ -48,25 +46,25 @@ context 'with all valid' do before(:each) do children.each do |child| - child.stub(valid?: true) + allow(child).to receive(:valid?).and_return(true) end end it 'does not add error on :children' do group.valid? - group.errors[:children].should_not include(error) + expect(group.errors[:children]).not_to include(error) end end context 'with later valid' do before(:each) do - children.first.stub(valid?: false) - children.second.stub(valid?: true) + allow(children.first).to receive(:valid?).and_return(false) + allow(children.second).to receive(:valid?).and_return(true) end it 'does not short-circuit and validates all children' do - children.second.should_receive(:valid?).and_return(true) + expect(children.second).to receive(:valid?).and_return(true) children_valid end @@ -74,7 +72,7 @@ it 'should add error on :children' do group.valid? - group.errors[:children].should include(error) + expect(group.errors[:children]).to include(error) end end end @@ -87,7 +85,7 @@ it 'does not add error on :children' do group.valid? - group.errors[:children].should_not include(error) + expect(group.errors[:children]).not_to include(error) end end end @@ -100,7 +98,7 @@ end context 'default' do - it { should == [] } + it { is_expected.to eq([]) } end context 'with attribute' do @@ -117,7 +115,7 @@ end it 'is the value passed with :children to #new' do - children.should == expected_children + expect(children).to eq(expected_children) end end end diff --git a/spec/app/models/metasploit/model/search/operation/group/intersection_spec.rb b/spec/app/models/metasploit/model/search/operation/group/intersection_spec.rb index 80a420be..b810aa12 100644 --- a/spec/app/models/metasploit/model/search/operation/group/intersection_spec.rb +++ b/spec/app/models/metasploit/model/search/operation/group/intersection_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Group::Intersection do - it { should be_a Metasploit::Model::Search::Operation::Group::Base } +RSpec.describe Metasploit::Model::Search::Operation::Group::Intersection, type: :model do + it { is_expected.to be_a Metasploit::Model::Search::Operation::Group::Base } end \ No newline at end of file diff --git a/spec/app/models/metasploit/model/search/operation/group/union_spec.rb b/spec/app/models/metasploit/model/search/operation/group/union_spec.rb index 4dcef0db..6e2c2a1c 100644 --- a/spec/app/models/metasploit/model/search/operation/group/union_spec.rb +++ b/spec/app/models/metasploit/model/search/operation/group/union_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Group::Union do - it { should be_a Metasploit::Model::Search::Operation::Group::Base } +RSpec.describe Metasploit::Model::Search::Operation::Group::Union, type: :model do + it { is_expected.to be_a Metasploit::Model::Search::Operation::Group::Base } end \ No newline at end of file diff --git a/spec/app/models/metasploit/model/search/operation/integer_spec.rb b/spec/app/models/metasploit/model/search/operation/integer_spec.rb index c6f23035..681675ed 100644 --- a/spec/app/models/metasploit/model/search/operation/integer_spec.rb +++ b/spec/app/models/metasploit/model/search/operation/integer_spec.rb @@ -1,8 +1,6 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Integer do +RSpec.describe Metasploit::Model::Search::Operation::Integer, type: :model do context 'validation' do - it { should validate_numericality_of(:value).only_integer } + it { is_expected.to validate_numericality_of(:value).only_integer } end it_should_behave_like 'Metasploit::Model::Search::Operation::Value::Integer' diff --git a/spec/app/models/metasploit/model/search/operation/null_spec.rb b/spec/app/models/metasploit/model/search/operation/null_spec.rb index a45129cf..96dc6c23 100644 --- a/spec/app/models/metasploit/model/search/operation/null_spec.rb +++ b/spec/app/models/metasploit/model/search/operation/null_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Null do +RSpec.describe Metasploit::Model::Search::Operation::Null, type: :model do context 'validation' do context 'operator' do context 'null' do @@ -41,7 +39,7 @@ end it 'should not record error' do - errors.should_not include(error) + expect(errors).not_to include(error) end end @@ -51,11 +49,11 @@ end it 'should record error' do - errors.should include(error) + expect(errors).to include(error) end it 'should have no other errors, so that it would be valid without this type check on operator' do - operation.errors.size.should == 1 + expect(operation.errors.size).to eq(1) end end end diff --git a/spec/app/models/metasploit/model/search/operation/set/integer_spec.rb b/spec/app/models/metasploit/model/search/operation/set/integer_spec.rb index 4c038df5..b3a74aa3 100644 --- a/spec/app/models/metasploit/model/search/operation/set/integer_spec.rb +++ b/spec/app/models/metasploit/model/search/operation/set/integer_spec.rb @@ -1,7 +1,5 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Set::Integer do - it { should be_a Metasploit::Model::Search::Operation::Set } +RSpec.describe Metasploit::Model::Search::Operation::Set::Integer, type: :model do + it { is_expected.to be_a Metasploit::Model::Search::Operation::Set } it_should_behave_like 'Metasploit::Model::Search::Operation::Value::Integer' end \ No newline at end of file diff --git a/spec/app/models/metasploit/model/search/operation/set/string_spec.rb b/spec/app/models/metasploit/model/search/operation/set/string_spec.rb index 519c80c1..3149145a 100644 --- a/spec/app/models/metasploit/model/search/operation/set/string_spec.rb +++ b/spec/app/models/metasploit/model/search/operation/set/string_spec.rb @@ -1,7 +1,5 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Set::String do - it { should be_a Metasploit::Model::Search::Operation::Set } +RSpec.describe Metasploit::Model::Search::Operation::Set::String, type: :model do + it { is_expected.to be_a Metasploit::Model::Search::Operation::Set } it_should_behave_like 'Metasploit::Model::Search::Operation::Value::String' end \ No newline at end of file diff --git a/spec/app/models/metasploit/model/search/operation/set_spec.rb b/spec/app/models/metasploit/model/search/operation/set_spec.rb index a1c292a7..f95d7718 100644 --- a/spec/app/models/metasploit/model/search/operation/set_spec.rb +++ b/spec/app/models/metasploit/model/search/operation/set_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Set do +RSpec.describe Metasploit::Model::Search::Operation::Set, type: :model do subject(:set) do described_class.new( operator: operator, @@ -97,7 +95,7 @@ attribute_set.sample end - it { should_not include(error) } + it { is_expected.not_to include(error) } end context 'without value in attribute_set' do @@ -105,7 +103,7 @@ :not_an_member end - it { should include(error) } + it { is_expected.to include(error) } end end @@ -118,7 +116,7 @@ nil end - it { should_not include(error) } + it { is_expected.not_to include(error) } end end end diff --git a/spec/app/models/metasploit/model/search/operation/string_spec.rb b/spec/app/models/metasploit/model/search/operation/string_spec.rb index 9224db11..b431173b 100644 --- a/spec/app/models/metasploit/model/search/operation/string_spec.rb +++ b/spec/app/models/metasploit/model/search/operation/string_spec.rb @@ -1,8 +1,6 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::String do +RSpec.describe Metasploit::Model::Search::Operation::String, type: :model do context 'validation' do - it { should validate_presence_of(:value) } + it { is_expected.to validate_presence_of(:value) } end it_should_behave_like 'Metasploit::Model::Search::Operation::Value::String' diff --git a/spec/app/models/metasploit/model/search/operator/association_spec.rb b/spec/app/models/metasploit/model/search/operator/association_spec.rb index ff81d0c7..b0bd6461 100644 --- a/spec/app/models/metasploit/model/search/operator/association_spec.rb +++ b/spec/app/models/metasploit/model/search/operator/association_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operator::Association do +RSpec.describe Metasploit::Model::Search::Operator::Association, type: :model do subject(:operator) do described_class.new( :association => association, @@ -16,11 +14,11 @@ double('Metasploit::Model::Search::Operator::Base') end - it { should be_a Metasploit::Model::Search::Operator::Base } + it { is_expected.to be_a Metasploit::Model::Search::Operator::Base } context 'validations' do - it { should validate_presence_of(:association) } - it { should validate_presence_of(:source_operator) } + it { is_expected.to validate_presence_of(:association) } + it { is_expected.to validate_presence_of(:source_operator) } end context '#help' do @@ -51,7 +49,7 @@ 'source_operator_name' } - it { should be_a Symbol } + it { is_expected.to be_a Symbol } it 'should be .' do expect(name).to eq :"#{association}.#{source_operator_name}" @@ -81,7 +79,7 @@ } } - it { should be_a Metasploit::Model::Search::Operation::Association } + it { is_expected.to be_a Metasploit::Model::Search::Operation::Association } context 'Metasploit::Model::Search::Operation::Association' do context '#operator' do diff --git a/spec/app/models/metasploit/model/search/operator/attribute_spec.rb b/spec/app/models/metasploit/model/search/operator/attribute_spec.rb index 0fe87d78..f81baf20 100644 --- a/spec/app/models/metasploit/model/search/operator/attribute_spec.rb +++ b/spec/app/models/metasploit/model/search/operator/attribute_spec.rb @@ -1,7 +1,5 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operator::Attribute do - it { should be_a Metasploit::Model::Search::Operator::Single } +RSpec.describe Metasploit::Model::Search::Operator::Attribute, type: :model do + it { is_expected.to be_a Metasploit::Model::Search::Operator::Single } context 'CONSTANTS' do context 'TYPES' do @@ -9,30 +7,30 @@ described_class::TYPES end - it { should include(:boolean) } - it { should include(:date) } + it { is_expected.to include(:boolean) } + it { is_expected.to include(:date) } it { - should include( + is_expected.to include( { set: :integer } ) } it { - should include( + is_expected.to include( { set: :string } ) } - it { should include(:integer) } - it { should include(:string) } + it { is_expected.to include(:integer) } + it { is_expected.to include(:string) } end end context 'validations' do - it { should validate_presence_of(:attribute) } - it { should ensure_inclusion_of(:type).in_array(described_class::TYPES) } + it { is_expected.to validate_presence_of(:attribute) } + it { is_expected.to validate_inclusion_of(:type).in_array(described_class::TYPES) } end context '#attribute_enumerable' do @@ -77,7 +75,7 @@ end it 'should be #klass #_set' do - attribute_set.should == expected_attribute_set + expect(attribute_set).to eq(expected_attribute_set) end end end @@ -98,7 +96,7 @@ end it 'should be #attribute' do - name.should == attribute + expect(name).to eq(attribute) end end -end \ No newline at end of file +end diff --git a/spec/app/models/metasploit/model/search/operator/base_spec.rb b/spec/app/models/metasploit/model/search/operator/base_spec.rb index 15f2896c..21df9455 100644 --- a/spec/app/models/metasploit/model/search/operator/base_spec.rb +++ b/spec/app/models/metasploit/model/search/operator/base_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operator::Base do +RSpec.describe Metasploit::Model::Search::Operator::Base, type: :model do subject(:operator) do described_class.new end @@ -12,12 +10,12 @@ before(:each) do # have to stub since it's not implemented on base - operator.stub(name: name) + allow(operator).to receive(:name).and_return(name) end end context 'validations' do - it { should validate_presence_of(:klass) } + it { is_expected.to validate_presence_of(:klass) } end context '#name' do diff --git a/spec/app/models/metasploit/model/search/operator/delegation_spec.rb b/spec/app/models/metasploit/model/search/operator/delegation_spec.rb index 95979ead..707435fc 100644 --- a/spec/app/models/metasploit/model/search/operator/delegation_spec.rb +++ b/spec/app/models/metasploit/model/search/operator/delegation_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operator::Delegation do +RSpec.describe Metasploit::Model::Search::Operator::Delegation, type: :model do subject(:operator) do described_class.new( :klass => klass @@ -11,7 +9,7 @@ Class.new end - it { should be_a Metasploit::Model::Search::Operator::Base } + it { is_expected.to be_a Metasploit::Model::Search::Operator::Base } context 'operator_name' do subject(:operator_name) do @@ -32,7 +30,7 @@ end it 'should remove namespace' do - operator_name.should == base_name.downcase.to_sym + expect(operator_name).to eq(base_name.downcase.to_sym) end end @@ -42,7 +40,7 @@ end it 'should convert name to underscore' do - operator_name.should == :camel_case + expect(operator_name).to eq(:camel_case) end end end @@ -67,17 +65,21 @@ end before(:each) do - klass.stub(:search_operator_by_name => search_operator_by_name) + outer_search_operator_by_name = search_operator_by_name + + klass.send(:define_singleton_method, :search_operator_by_name) do + outer_search_operator_by_name + end end it 'should convert formatted_operator to Symbol' do - formatted_operator.should_receive(:to_sym) + expect(formatted_operator).to receive(:to_sym) named_operator end it 'should look up operator name in search_operator_by_name of #klass' do - named_operator.should == search_operator + expect(named_operator).to eq(search_operator) end context 'with name not in klass.search_operator_by_name' do @@ -100,9 +102,9 @@ it 'should delegate to operator_name' do operator_name = double('Operator Name') - operator.class.stub(:operator_name => operator_name) + allow(operator.class).to receive(:operator_name).and_return(operator_name) - name.should == operator_name + expect(name).to eq(operator_name) end end end \ No newline at end of file diff --git a/spec/app/models/metasploit/model/search/operator/group/base_spec.rb b/spec/app/models/metasploit/model/search/operator/group/base_spec.rb index 4a6ac77f..2abf161c 100644 --- a/spec/app/models/metasploit/model/search/operator/group/base_spec.rb +++ b/spec/app/models/metasploit/model/search/operator/group/base_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operator::Group::Base do +RSpec.describe Metasploit::Model::Search::Operator::Group::Base, type: :model do subject(:operator) do described_class.new end @@ -50,10 +48,10 @@ # before(:each) do - operator.stub(:children => children) + allow(operator).to receive(:children).and_return(children) end - it { should be_a Metasploit::Model::Search::Operation::Group::Base } + it { is_expected.to be_a Metasploit::Model::Search::Operation::Group::Base } context 'children' do subject(:operation_children) do @@ -75,7 +73,7 @@ end it 'should be the operator itself' do - operation_operator.should == operator + expect(operation_operator).to eq(operator) end end @@ -85,7 +83,7 @@ end it 'should be formatted value' do - value.should == formatted_value + expect(value).to eq(formatted_value) end end end diff --git a/spec/app/models/metasploit/model/search/operator/group/intersection_spec.rb b/spec/app/models/metasploit/model/search/operator/group/intersection_spec.rb index 65b3f859..08f668b8 100644 --- a/spec/app/models/metasploit/model/search/operator/group/intersection_spec.rb +++ b/spec/app/models/metasploit/model/search/operator/group/intersection_spec.rb @@ -1,13 +1,11 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operator::Group::Intersection do - it { should be_a Metasploit::Model::Search::Operator::Group::Base } +RSpec.describe Metasploit::Model::Search::Operator::Group::Intersection, type: :model do + it { is_expected.to be_a Metasploit::Model::Search::Operator::Group::Base } context 'operation_class_name' do subject(:operation_class_name) { described_class.operation_class_name } - it { should == 'Metasploit::Model::Search::Operation::Group::Intersection' } + it { is_expected.to eq('Metasploit::Model::Search::Operation::Group::Intersection') } end end \ No newline at end of file diff --git a/spec/app/models/metasploit/model/search/operator/group/union_spec.rb b/spec/app/models/metasploit/model/search/operator/group/union_spec.rb index 57df42b5..ee863f5d 100644 --- a/spec/app/models/metasploit/model/search/operator/group/union_spec.rb +++ b/spec/app/models/metasploit/model/search/operator/group/union_spec.rb @@ -1,13 +1,11 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operator::Group::Union do - it { should be_a Metasploit::Model::Search::Operator::Group::Base } +RSpec.describe Metasploit::Model::Search::Operator::Group::Union, type: :model do + it { is_expected.to be_a Metasploit::Model::Search::Operator::Group::Base } context 'operation_class_name' do subject(:operation_class_name) { described_class.operation_class_name } - it { should == 'Metasploit::Model::Search::Operation::Group::Union' } + it { is_expected.to eq('Metasploit::Model::Search::Operation::Group::Union') } end end \ No newline at end of file diff --git a/spec/app/models/metasploit/model/search/operator/null_spec.rb b/spec/app/models/metasploit/model/search/operator/null_spec.rb index 8e3c49ab..432c9468 100644 --- a/spec/app/models/metasploit/model/search/operator/null_spec.rb +++ b/spec/app/models/metasploit/model/search/operator/null_spec.rb @@ -1,11 +1,9 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operator::Null do +RSpec.describe Metasploit::Model::Search::Operator::Null, type: :model do subject(:operator) do described_class.new end - it { should be_a Metasploit::Model::Search::Operator::Single } + it { is_expected.to be_a Metasploit::Model::Search::Operator::Single } context 'validations' do context 'name' do @@ -18,7 +16,7 @@ end it 'should record error' do - operator.errors[:name].should include(error) + expect(operator.errors[:name]).to include(error) end end end @@ -28,7 +26,7 @@ operator.type end - it { should be_nil } + it { is_expected.to be_nil } end context '#operation_class' do @@ -36,6 +34,6 @@ operator.send(:operation_class) end - it { should == Metasploit::Model::Search::Operation::Null } + it { is_expected.to eq(Metasploit::Model::Search::Operation::Null) } end end \ No newline at end of file diff --git a/spec/app/models/metasploit/model/search/operator/single_spec.rb b/spec/app/models/metasploit/model/search/operator/single_spec.rb index 98735c61..585f1b16 100644 --- a/spec/app/models/metasploit/model/search/operator/single_spec.rb +++ b/spec/app/models/metasploit/model/search/operator/single_spec.rb @@ -1,11 +1,9 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operator::Single do +RSpec.describe Metasploit::Model::Search::Operator::Single, type: :model do subject(:operator) do described_class.new end - it { should be_a Metasploit::Model::Search::Operator::Base } + it { is_expected.to be_a Metasploit::Model::Search::Operator::Base } context 'CONSTANTS' do context 'MODULE_SEPARATOR' do @@ -13,7 +11,7 @@ described_class::MODULE_SEPARATOR end - it { should == '::' } + it { is_expected.to eq('::') } end context 'OPERATION_NAMESPACE_NAME' do @@ -21,7 +19,7 @@ described_class::OPERATION_NAMESPACE_NAME end - it { should == 'Metasploit::Model::Search::Operation' } + it { is_expected.to eq('Metasploit::Model::Search::Operation') } end end @@ -67,7 +65,7 @@ end it 'should be the constant_name of the key and value separated by MODULE_SEPARATOR' do - constant_name.should == "#{key_constant_name}#{described_class::MODULE_SEPARATOR}#{value_constant_name}" + expect(constant_name).to eq("#{key_constant_name}#{described_class::MODULE_SEPARATOR}#{value_constant_name}") end end @@ -93,7 +91,7 @@ end it 'should constantize string version of Symbol' do - constant_name.should == 'Integer' + expect(constant_name).to eq('Integer') end end @@ -124,20 +122,20 @@ end before(:each) do - operator.stub(:operation_class => operation_class) + allow(operator).to receive(:operation_class).and_return(operation_class) end it 'should call new on #operation_class' do - operation_class.should_receive(:new).with(:value => formatted_value, :operator => operator) + expect(operation_class).to receive(:new).with(:value => formatted_value, :operator => operator) operate_on end it 'should return instance of #operation_class' do operation = double('Operation') - operation_class.stub(:new => operation) + allow(operation_class).to receive(:new).and_return(operation) - operate_on.should == operation + expect(operate_on).to eq(operation) end end @@ -147,7 +145,7 @@ end before(:each) do - operator.stub(:type => type) + allow(operator).to receive(:type).and_return(type) end context 'type' do @@ -156,7 +154,7 @@ :boolean end - it { should == Metasploit::Model::Search::Operation::Boolean } + it { is_expected.to eq(Metasploit::Model::Search::Operation::Boolean) } end context 'with :date' do @@ -164,7 +162,7 @@ :date end - it { should == Metasploit::Model::Search::Operation::Date } + it { is_expected.to eq(Metasploit::Model::Search::Operation::Date) } end context 'with set: :integer' do @@ -174,7 +172,7 @@ } end - it { should == Metasploit::Model::Search::Operation::Set::Integer } + it { is_expected.to eq(Metasploit::Model::Search::Operation::Set::Integer) } end context 'with set: :string' do @@ -184,7 +182,7 @@ } end - it { should == Metasploit::Model::Search::Operation::Set::String } + it { is_expected.to eq(Metasploit::Model::Search::Operation::Set::String) } end context 'with :integer' do @@ -192,7 +190,7 @@ :integer end - it { should == Metasploit::Model::Search::Operation::Integer } + it { is_expected.to eq(Metasploit::Model::Search::Operation::Integer) } end context 'with :string' do @@ -200,7 +198,7 @@ :string end - it { should == Metasploit::Model::Search::Operation::String } + it { is_expected.to eq(Metasploit::Model::Search::Operation::String) } end context 'with nil' do @@ -213,7 +211,7 @@ end before(:each) do - operator.stub(:name => name) + allow(operator).to receive(:name).and_return(name) end it 'should raise ArgumentError' do @@ -233,7 +231,7 @@ end before(:each) do - operator.stub(:type => type) + allow(operator).to receive(:type).and_return(type) end context 'type' do @@ -242,7 +240,7 @@ :boolean end - it { should == 'Metasploit::Model::Search::Operation::Boolean' } + it { is_expected.to eq('Metasploit::Model::Search::Operation::Boolean') } end context 'with :date' do @@ -250,7 +248,7 @@ :date end - it { should == 'Metasploit::Model::Search::Operation::Date' } + it { is_expected.to eq('Metasploit::Model::Search::Operation::Date') } end context 'with set: :integer' do @@ -260,7 +258,7 @@ } end - it { should == 'Metasploit::Model::Search::Operation::Set::Integer' } + it { is_expected.to eq('Metasploit::Model::Search::Operation::Set::Integer') } end context 'with set: :string' do @@ -270,7 +268,7 @@ } end - it { should == 'Metasploit::Model::Search::Operation::Set::String' } + it { is_expected.to eq('Metasploit::Model::Search::Operation::Set::String') } end context 'with :integer' do @@ -278,7 +276,7 @@ :integer end - it { should == 'Metasploit::Model::Search::Operation::Integer' } + it { is_expected.to eq('Metasploit::Model::Search::Operation::Integer') } end context 'with :string' do @@ -286,7 +284,7 @@ :string end - it { should == 'Metasploit::Model::Search::Operation::String' } + it { is_expected.to eq('Metasploit::Model::Search::Operation::String') } end context 'with nil' do @@ -299,7 +297,7 @@ end before(:each) do - operator.stub(:name => name) + allow(operator).to receive(:name).and_return(name) end it 'should raise ArgumentError' do diff --git a/spec/app/models/metasploit/model/search/query_spec.rb b/spec/app/models/metasploit/model/search/query_spec.rb index f9cd09b4..3be09eb8 100644 --- a/spec/app/models/metasploit/model/search/query_spec.rb +++ b/spec/app/models/metasploit/model/search/query_spec.rb @@ -1,8 +1,6 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Query do +RSpec.describe Metasploit::Model::Search::Query, type: :model do context 'validations' do - it { should validate_presence_of :klass } + it { is_expected.to validate_presence_of :klass } context 'operations' do let(:errors) do @@ -45,11 +43,11 @@ end it 'should have no operations' do - query.operations.length.should == 0 + expect(query.operations.length).to eq(0) end it 'should record error on operations' do - errors.should include(error) + expect(errors).to include(error) end end @@ -59,7 +57,7 @@ end it 'should not record error on operations' do - errors.should_not include(error) + expect(errors).not_to include(error) end end end @@ -75,7 +73,7 @@ before(:each) do operation = double('Invalid Operation', :valid? => valid) - query.stub(:operations).and_return([operation]) + allow(query).to receive(:operations).and_return([operation]) end context 'with invalid operation' do @@ -84,7 +82,7 @@ end it 'should record error on operations' do - errors.should_not include(error) + expect(errors).not_to include(error) end end @@ -94,7 +92,7 @@ end it 'should not record error on options' do - errors.should_not include(error) + expect(errors).not_to include(error) end end end @@ -117,11 +115,11 @@ end it 'should include operation with space in value' do - formatted_operations.should include('formatted_operator1:formatted value:1') + expect(formatted_operations).to include('formatted_operator1:formatted value:1') end it 'should include operation without space in value' do - formatted_operations.should include('formatted_operator2:formatted_value2') + expect(formatted_operations).to include('formatted_operator2:formatted_value2') end end @@ -172,7 +170,7 @@ end it 'should equal attribute passed to #initialize' do - formatted_operations.should == expected_formatted_operations + expect(formatted_operations).to eq(expected_formatted_operations) end end @@ -208,7 +206,7 @@ end it 'should parse #formatted with formatted_operations' do - described_class.should_receive(:formatted_operations).with(formatted).and_return([]) + expect(described_class).to receive(:formatted_operations).with(formatted).and_return([]) formatted_operations end @@ -232,7 +230,7 @@ end it 'should use attribute passed to #initialize' do - operations.should == expected_operations + expect(operations).to eq(expected_operations) end end @@ -272,7 +270,7 @@ end it 'should call #formatted_operations' do - query.should_receive(:formatted_operations).and_return([]) + expect(query).to receive(:formatted_operations).and_return([]) operations end @@ -299,14 +297,14 @@ :boolean end - it { should be_a Metasploit::Model::Search::Operation::Boolean } + it { is_expected.to be_a Metasploit::Model::Search::Operation::Boolean } context "with 'true'" do let(:formatted_value) do 'true' end - it { should be_valid } + it { is_expected.to be_valid } end context "with 'false'" do @@ -314,7 +312,7 @@ 'false' end - it { should be_valid } + it { is_expected.to be_valid } end context "without 'false' or 'true'" do @@ -322,7 +320,7 @@ 'no' end - it { should_not be_valid } + it { is_expected.to_not be_valid } end end @@ -331,14 +329,14 @@ :date end - it { should be_a Metasploit::Model::Search::Operation::Date } + it { is_expected.to be_a Metasploit::Model::Search::Operation::Date } context 'with date' do let(:formatted_value) do Date.today.to_s end - it { should be_valid } + it { is_expected.to be_valid } end context 'without date' do @@ -346,7 +344,7 @@ 'yesterday' end - it { should_not be_valid } + it { is_expected.to_not be_valid } end end @@ -355,14 +353,14 @@ :integer end - it { should be_a Metasploit::Model::Search::Operation::Integer } + it { is_expected.to be_a Metasploit::Model::Search::Operation::Integer } context 'with integer' do let(:formatted_value) do '100' end - it { should be_valid } + it { is_expected.to be_valid } end context 'with float' do @@ -370,7 +368,7 @@ '100.5' end - it { should be_invalid } + it { is_expected.to be_invalid } end context 'with integer embedded in text' do @@ -378,7 +376,7 @@ 'a2c' end - it { should be_invalid } + it { is_expected.to be_invalid } end end @@ -387,14 +385,14 @@ :string end - it { should be_a Metasploit::Model::Search::Operation::String } + it { is_expected.to be_a Metasploit::Model::Search::Operation::String } context 'with value' do let(:formatted_value) do 'formatted_value' end - it { should be_valid } + it { is_expected.to be_valid } end context 'without value' do @@ -402,7 +400,7 @@ '' end - it { should_not be_valid } + it { is_expected.to_not be_valid } end end end @@ -420,9 +418,9 @@ 'unknown_value' end - it { should be_a Metasploit::Model::Search::Operation::Base } + it { is_expected.to be_a Metasploit::Model::Search::Operation::Base } - it { should be_invalid } + it { is_expected.to be_invalid } end end end @@ -468,7 +466,7 @@ end it 'should have correct number of groups' do - operations_by_operator.length.should == @operators.length + expect(operations_by_operator.length).to eq(@operators.length) end it 'should have correct value for each operator' do @@ -489,7 +487,7 @@ query end - it { should be_valid } + it { is_expected.to be_valid } end end @@ -503,7 +501,7 @@ query end - it { should_not be_valid } + it { is_expected.to_not be_valid } end end end @@ -542,7 +540,7 @@ context 'with String' do it 'should find operator' do - parse_operator.should == @operator + expect(parse_operator).to eq(@operator) end end @@ -552,7 +550,7 @@ end it 'should find operator' do - parse_operator.should == @operator + expect(parse_operator).to eq(@operator) end end end @@ -562,7 +560,7 @@ 'unknown_operator' end - it { should be_a Metasploit::Model::Search::Operator::Null } + it { is_expected.to be_a Metasploit::Model::Search::Operator::Null } end end @@ -599,7 +597,7 @@ tree end - it { should be_a Metasploit::Model::Search::Group::Intersection } + it { is_expected.to be_a Metasploit::Model::Search::Group::Intersection } context 'children' do subject(:children) do @@ -608,17 +606,17 @@ it 'should be an Array' do children.each do |child| - child.should be_a Metasploit::Model::Search::Group::Union + expect(child).to be_a Metasploit::Model::Search::Group::Union end end it 'should have same operator for each child of a union' do children.each do |child| - operator_set = child.children.inject(Set.new) { |operator_set, operation| - operator_set.add operation.operator + operator_set = child.children.inject(Set.new) { |block_operator_set, operation| + block_operator_set.add operation.operator } - operator_set.length.should == 1 + expect(operator_set.length).to eq(1) end end @@ -635,7 +633,7 @@ it 'should be Array' do grandchildren.each do |grandchild| - grandchild.should be_a Metasploit::Model::Search::Operation::Base + expect(grandchild).to be_a Metasploit::Model::Search::Operation::Base end end end @@ -701,15 +699,15 @@ end it 'should return a new query' do - without_operator.should_not be query + expect(without_operator).not_to be query end it 'should not have operations on the removed operator' do - without_operator.operations_by_operator[filtered_operator].should be_blank + expect(without_operator.operations_by_operator[filtered_operator]).to be_blank end it 'should have same #klass as this query' do - without_operator.klass.should == query.klass + expect(without_operator.klass).to eq(query.klass) end context 'with no other operators' do @@ -719,11 +717,11 @@ ] end - it { should_not be_valid } + it { is_expected.to_not be_valid } end context 'with other operators' do - it { should be_valid } + it { is_expected.to be_valid } end end @@ -735,7 +733,7 @@ end it 'should return this query' do - without_operator.should be query + expect(without_operator).to be query end end end diff --git a/spec/app/models/metasploit/model/visitation/visitor_spec.rb b/spec/app/models/metasploit/model/visitation/visitor_spec.rb index 493a13c3..db78b596 100644 --- a/spec/app/models/metasploit/model/visitation/visitor_spec.rb +++ b/spec/app/models/metasploit/model/visitation/visitor_spec.rb @@ -1,10 +1,8 @@ -require 'spec_helper' - -describe Metasploit::Model::Visitation::Visitor do +RSpec.describe Metasploit::Model::Visitation::Visitor, type: :model do context 'validations' do - it { should validate_presence_of :block } - it { should validate_presence_of :module_name } - it { should validate_presence_of :parent } + it { is_expected.to validate_presence_of :block } + it { is_expected.to validate_presence_of :module_name } + it { is_expected.to validate_presence_of :parent } end context '#initialize' do @@ -31,15 +29,15 @@ end it 'should set #block from &block' do - instance.block.should == block + expect(instance.block).to eq(block) end it 'should set #module_name from :module_name' do - instance.module_name.should == module_name + expect(instance.module_name).to eq(module_name) end it 'should set #parent from :parent' do - instance.parent.should == parent + expect(instance.parent).to eq(parent) end end end \ No newline at end of file diff --git a/spec/app/validators/ip_format_validator_spec.rb b/spec/app/validators/ip_format_validator_spec.rb index 5927e1a2..fcfe531d 100644 --- a/spec/app/validators/ip_format_validator_spec.rb +++ b/spec/app/validators/ip_format_validator_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe IpFormatValidator do +RSpec.describe IpFormatValidator do subject(:ip_format_validator) do described_class.new( :attributes => attributes @@ -55,7 +53,7 @@ it 'should not record any errors' do validate_each - record.errors.should be_empty + expect(record.errors).to be_empty end end @@ -67,7 +65,7 @@ it 'should not record any errors' do validate_each - record.errors.should be_empty + expect(record.errors).to be_empty end end @@ -79,7 +77,7 @@ it 'should record error' do validate_each - record.errors[attribute].should include("#{error} and not an IPv4 address range in CIDR or netmask notation") + expect(record.errors[attribute]).to include("#{error} and not an IPv4 address range in CIDR or netmask notation") end end @@ -91,7 +89,7 @@ it 'should record error' do validate_each - record.errors[attribute].should include("#{error} and not an IPv6 address range in CIDR or netmask notation") + expect(record.errors[attribute]).to include("#{error} and not an IPv6 address range in CIDR or netmask notation") end end @@ -103,7 +101,7 @@ it 'should record error' do validate_each - record.errors[attribute].should include(error) + expect(record.errors[attribute]).to include(error) end end @@ -117,7 +115,7 @@ it 'should record error on attribute' do validate_each - record.errors[attribute].should include(error) + expect(record.errors[attribute]).to include(error) end end end diff --git a/spec/app/validators/nil_validator_spec.rb b/spec/app/validators/nil_validator_spec.rb index 9eb453f4..f8b278c7 100644 --- a/spec/app/validators/nil_validator_spec.rb +++ b/spec/app/validators/nil_validator_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe NilValidator do +RSpec.describe NilValidator do subject(:nil_validator) do described_class.new( :attributes => attributes @@ -50,7 +48,7 @@ it 'should record error on attribute' do validate_each - record.errors[attribute].should include('must be nil') + expect(record.errors[attribute]).to include('must be nil') end end @@ -62,7 +60,7 @@ it 'should not record any error' do validate_each - record.errors.should be_empty + expect(record.errors).to be_empty end end end diff --git a/spec/app/validators/parameters_validator_spec.rb b/spec/app/validators/parameters_validator_spec.rb index 64d17cd2..9e9decf6 100644 --- a/spec/app/validators/parameters_validator_spec.rb +++ b/spec/app/validators/parameters_validator_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe ParametersValidator do +RSpec.describe ParametersValidator do subject(:parameters_validator) do described_class.new( :attributes => attributes @@ -29,7 +27,7 @@ context 'CONSTANTS' do it 'should define TYPE_SIGNATURE_SENTENCE' do - described_class::TYPE_SIGNATURE_SENTENCE.should == type_signature_sentence + expect(described_class::TYPE_SIGNATURE_SENTENCE).to eq(type_signature_sentence) end end @@ -48,7 +46,7 @@ end it 'should include prefix' do - error_at.should include(prefix) + expect(error_at).to include(prefix) end it 'should include location_clause in same sentence as prefix' do @@ -58,11 +56,11 @@ :index => index ) - error_at.should include("#{prefix} #{location_clause}.") + expect(error_at).to include("#{prefix} #{location_clause}.") end it 'should include TYPE_SIGNATURE_SENTENCE' do - error_at.should include(type_signature_sentence) + expect(error_at).to include(type_signature_sentence) end end @@ -81,9 +79,9 @@ end it 'should include extreme in prefix' do - parameters_validator.should_receive(:error_at) do |*args| + expect(parameters_validator).to receive(:error_at) do |*args| options = args.first - options[:prefix].should include(extreme.to_s) + expect(options[:prefix]).to include(extreme.to_s) end length_error_at @@ -100,11 +98,11 @@ end it 'should include numerical index' do - location_clause.should include("at index #{index}") + expect(location_clause).to include("at index #{index}") end it 'should include inspect of element' do - location_clause.should include(element.inspect) + expect(location_clause).to include(element.inspect) end end @@ -144,7 +142,7 @@ def validate_each end it 'should call #length_error_at with :extreme => :few' do - parameters_validator.should_receive(:length_error_at).with( + expect(parameters_validator).to receive(:length_error_at).with( hash_including( :extreme => :few ) @@ -156,7 +154,7 @@ def validate_each it 'should record error' do validate_each - errors.should_not be_empty + expect(errors).not_to be_empty end end @@ -166,7 +164,7 @@ def validate_each end it 'should call #length_error_at with :extreme => :many' do - parameters_validator.should_receive(:length_error_at).with( + expect(parameters_validator).to receive(:length_error_at).with( hash_including( :extreme => :many ) @@ -178,7 +176,7 @@ def validate_each it 'should record error' do validate_each - errors.should_not be_empty + expect(errors).not_to be_empty end end @@ -203,7 +201,7 @@ def validate_each end it 'should call error_at with blank parameter name prefix' do - parameters_validator.should_receive(:error_at).with( + expect(parameters_validator).to receive(:error_at).with( hash_including( :prefix => 'has blank parameter name' ) @@ -215,7 +213,7 @@ def validate_each it 'should record error' do validate_each - errors.should_not be_empty + expect(errors).not_to be_empty end end @@ -227,7 +225,7 @@ def validate_each it 'should not record error' do validate_each - errors.should be_blank + expect(errors).to be_blank end end end @@ -238,7 +236,7 @@ def validate_each end it 'should call error_at with non-String prefix' do - parameters_validator.should_receive(:error_at).with( + expect(parameters_validator).to receive(:error_at).with( hash_including( :prefix => "has non-String parameter name (#{parameter_name.inspect})" ) @@ -250,7 +248,7 @@ def validate_each it 'should record error' do validate_each - errors.should_not be_empty + expect(errors).not_to be_empty end end end @@ -264,7 +262,7 @@ def validate_each it 'should not record error' do validate_each - errors.should be_blank + expect(errors).to be_blank end end @@ -274,7 +272,7 @@ def validate_each end it 'should call error_at with non-String prefix' do - parameters_validator.should_receive(:error_at).with( + expect(parameters_validator).to receive(:error_at).with( hash_including( :prefix => "has non-String parameter value (#{parameter_value.inspect})" ) @@ -286,7 +284,7 @@ def validate_each it 'should record error' do validate_each - errors.should_not be_empty + expect(errors).not_to be_empty end end end @@ -299,7 +297,7 @@ def validate_each end it 'should use #error_at with has non-Array for prefix' do - parameters_validator.should_receive(:error_at).with( + expect(parameters_validator).to receive(:error_at).with( hash_including( :prefix => 'has non-Array' ) @@ -311,7 +309,7 @@ def validate_each it 'should record error' do validate_each - errors.should_not be_empty + expect(errors).not_to be_empty end end end @@ -327,14 +325,16 @@ def validate_each end it 'should error that attribute is not an array' do - errors.any? { |error| - error.include? 'is not an Array.' - }.should be_true + expect( + errors.any? { |error| + error.include? 'is not an Array.' + } + ).to eq(true) end it 'should include TYPE_SIGNATURE_SENTENCE' do errors.each do |error| - error.should include(type_signature_sentence) + expect(error).to include(type_signature_sentence) end end end diff --git a/spec/app/validators/password_is_strong_validator_spec.rb b/spec/app/validators/password_is_strong_validator_spec.rb index 2ce61d86..980a81a3 100644 --- a/spec/app/validators/password_is_strong_validator_spec.rb +++ b/spec/app/validators/password_is_strong_validator_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe PasswordIsStrongValidator do +RSpec.describe PasswordIsStrongValidator do subject(:password_is_strong_validator) do described_class.new( :attributes => attributes @@ -27,7 +25,7 @@ 'aaaaa' end - it { should be_true } + it { is_expected.to eq(true) } end context 'with repeats of 2 characters' do @@ -35,7 +33,7 @@ 'abab' end - it { should be_true } + it { is_expected.to eq(true) } end context 'with repeats of 3 characters' do @@ -43,7 +41,7 @@ 'abcabc' end - it { should be_true } + it { is_expected.to eq(true) } end context 'with repeats of 4 characters' do @@ -51,7 +49,7 @@ 'abcdabcd' end - it { should be_true } + it { is_expected.to eq(true) } end context 'without any repeats' do @@ -59,7 +57,7 @@ 'abcdefgh' end - it { should be_false } + it { is_expected.to eq(false) } end end @@ -77,7 +75,7 @@ '' end - it { should be_false } + it { is_expected.to eq(false) } end context 'without blank password' do @@ -90,7 +88,7 @@ '' end - it { should be_false } + it { is_expected.to eq(false) } end context 'without blank username' do @@ -99,7 +97,7 @@ end it 'should escape username' do - Regexp.should_receive(:escape).with(username).and_call_original + expect(Regexp).to receive(:escape).with(username).and_call_original contains_username? end @@ -110,7 +108,7 @@ username.titleize end - it { should be_true } + it { is_expected.to eq(true) } end context 'of same case' do @@ -118,7 +116,7 @@ username end - it { should be_true } + it { is_expected.to eq(true) } end end end @@ -167,7 +165,7 @@ it 'should not record any error' do validate_each - record.errors.should be_empty + expect(record.errors).to be_empty end end @@ -180,7 +178,7 @@ it 'should record error on attributes' do validate_each - record.errors[attribute].should include('must contain letters, numbers, and at least one special character') + expect(record.errors[attribute]).to include('must contain letters, numbers, and at least one special character') end end @@ -201,7 +199,7 @@ it 'should record error on attribute' do validate_each - record.errors[attribute].should include('must not contain the username') + expect(record.errors[attribute]).to include('must not contain the username') end end @@ -214,7 +212,7 @@ it 'should record error on attribute' do validate_each - record.errors[attribute].should include('must not be a common password') + expect(record.errors[attribute]).to include('must not be a common password') end end @@ -227,7 +225,7 @@ it 'should record error on attribute' do validate_each - record.errors[attribute].should include('must not be a predictable sequence of characters') + expect(record.errors[attribute]).to include('must not be a predictable sequence of characters') end end @@ -239,7 +237,7 @@ it 'should not record any errors' do validate_each - record.errors.should be_empty + expect(record.errors).to be_empty end end end diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index df099fab..3d87b24b 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -1,6 +1,8 @@ require File.expand_path('../boot', __FILE__) -require 'rails/all' +# Pick the frameworks you want: +require 'active_model/railtie' +require "action_controller/railtie" Bundler.require(*Rails.groups) diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb index 4b7ab56c..71c78b18 100644 --- a/spec/dummy/config/environments/development.rb +++ b/spec/dummy/config/environments/development.rb @@ -16,9 +16,6 @@ # Print deprecation notices to the Rails logger config.active_support.deprecation = :log - # Only use best-standards-support built into browsers - config.action_dispatch.best_standards_support = :builtin - # Do not compress assets config.assets.compress = false diff --git a/spec/lib/metasploit/model/association/error_spec.rb b/spec/lib/metasploit/model/association/error_spec.rb index 96d1730c..b70abdf8 100644 --- a/spec/lib/metasploit/model/association/error_spec.rb +++ b/spec/lib/metasploit/model/association/error_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Association::Error do +RSpec.describe Metasploit::Model::Association::Error do context '#initialize' do let(:attributes) do { diff --git a/spec/lib/metasploit/model/association_spec.rb b/spec/lib/metasploit/model/association_spec.rb index 961c8976..3457b68f 100644 --- a/spec/lib/metasploit/model/association_spec.rb +++ b/spec/lib/metasploit/model/association_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Association do +RSpec.describe Metasploit::Model::Association do subject(:base_class) do described_class = self.described_class @@ -54,7 +52,7 @@ end it 'should be class on which association was called' do - model.should == base_class + expect(model).to eq(base_class) end end @@ -64,7 +62,7 @@ end it 'should be name passed to association as a Symbol' do - reflection_name.should == name.to_sym + expect(reflection_name).to eq(name.to_sym) end end @@ -74,7 +72,7 @@ end it 'should be :class_name passed to association' do - reflection_class_name.should == class_name + expect(reflection_class_name).to eq(class_name) end end end @@ -87,7 +85,7 @@ end it 'should default to empty Hash' do - association_by_name.should == {} + expect(association_by_name).to eq({}) end end @@ -119,7 +117,7 @@ end it 'should be class_name passed to association' do - reflection_class_name.should == class_name + expect(reflection_class_name).to eq(class_name) end end @@ -129,7 +127,7 @@ end it 'should have the reflected name' do - reflection.name.should == reflected_name + expect(reflection.name).to eq(reflected_name) end end end @@ -139,7 +137,7 @@ :unassociated_things end - it { should be_nil } + it { is_expected.to be_nil } end end end \ No newline at end of file diff --git a/spec/lib/metasploit/model/base_spec.rb b/spec/lib/metasploit/model/base_spec.rb index f92a5438..16dbf190 100644 --- a/spec/lib/metasploit/model/base_spec.rb +++ b/spec/lib/metasploit/model/base_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Base do +RSpec.describe Metasploit::Model::Base do subject(:base_class) do Class.new(described_class) end @@ -12,7 +10,7 @@ it 'should use public_send to set attributes' do attribute = :attribute value = double('Value') - base_class.any_instance.should_receive(:public_send).with("#{attribute}=", value) + expect_any_instance_of(base_class).to receive(:public_send).with("#{attribute}=", value) base_class.new(attribute => value) end @@ -28,7 +26,7 @@ end before(:each) do - base_instance.stub(:valid? => valid) + allow(base_instance).to receive(:valid?).and_return(valid) end context 'with valid' do diff --git a/spec/lib/metasploit/model/engine_spec.rb b/spec/lib/metasploit/model/engine_spec.rb index dffeecbe..cdfdb8b2 100644 --- a/spec/lib/metasploit/model/engine_spec.rb +++ b/spec/lib/metasploit/model/engine_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Engine do +RSpec.describe Metasploit::Model::Engine do context 'config' do subject(:config) do described_class.config @@ -21,7 +19,13 @@ options[:factory_girl] end - its([:dir]) { should == 'spec/factories' } + context 'dir' do + subject(:dir) { + factory_girl[:dir] + } + + it { is_expected.to eq('spec/factories') } + end end context 'rails' do @@ -29,10 +33,37 @@ options[:rails] end - its([:assets]) { should be_false } - its([:fixture_replacement]) { should == :factory_girl } - its([:helper]) { should be_false } - its([:test_framework]) { should == :rspec } + context 'assets' do + subject(:assets) { + rails[:assets] + } + + it { is_expected.to eq(false) } + end + + context 'fixture_replacement' do + subject(:fixture_replacement) { + rails[:fixture_replacement] + } + + it { is_expected.to eq(:factory_girl) } + end + + context 'helper' do + subject(:helper) { + rails[:helper] + } + + it { is_expected.to eq(false) } + end + + context 'test_framework' do + subject(:test_framework) { + rails[:test_framework] + } + + it { is_expected.to eq(:rspec) } + end end context 'rspec' do @@ -40,7 +71,13 @@ options[:rspec] end - its([:fixture]) { should be_false } + context 'fixture' do + subject(:fixture) { + rspec[:fixture] + } + + it { is_expected.to eq(false) } + end end end end @@ -61,7 +98,7 @@ end it 'should run after factory_girl.set_factory_paths' do - initializer.after.should == 'factory_girl.set_factory_paths' + expect(initializer.after).to eq('factory_girl.set_factory_paths') end context 'running' do @@ -73,7 +110,7 @@ def run it 'should prepend full path to spec/factories to FactoryGirl.definition_file_paths' do definition_file_path = Metasploit::Model::Engine.root.join('spec', 'factories') - FactoryGirl.definition_file_paths.should_receive(:unshift).with(definition_file_path) + expect(FactoryGirl.definition_file_paths).to receive(:unshift).with(definition_file_path) run end diff --git a/spec/lib/metasploit/model/file_spec.rb b/spec/lib/metasploit/model/file_spec.rb index 2c651dde..337e7bc6 100644 --- a/spec/lib/metasploit/model/file_spec.rb +++ b/spec/lib/metasploit/model/file_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::File do +RSpec.describe Metasploit::Model::File do unless RUBY_PLATFORM =~ /java/ && Gem::Version.new(JRUBY_VERSION) < Gem::Version.new('1.7.14') it 'aliases ::File' do expect(described_class).to equal(::File) @@ -38,12 +36,12 @@ def realpath if RUBY_PLATFORM =~ /java/ && Gem::Version.new(JRUBY_VERSION) < Gem::Version.new('1.7.14') it 'should be necessary because File.realpath does not resolve symlinks' do - File.realpath(symlink_pathname.to_path).should_not == real_pathname.to_path + expect(File.realpath(symlink_pathname.to_path)).not_to eq(real_pathname.to_path) end end it 'should resolve symlink to real (canonical) path' do - realpath.should == real_pathname.to_path + expect(realpath).to eq(real_pathname.to_path) end end end \ No newline at end of file diff --git a/spec/lib/metasploit/model/invalid_spec.rb b/spec/lib/metasploit/model/invalid_spec.rb index b844750e..0a9adc72 100644 --- a/spec/lib/metasploit/model/invalid_spec.rb +++ b/spec/lib/metasploit/model/invalid_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Invalid do +RSpec.describe Metasploit::Model::Invalid do subject(:invalid) do described_class.new(model) end @@ -15,16 +13,16 @@ end end - it { should be_a Metasploit::Model::Error } + it { is_expected.to be_a Metasploit::Model::Error } it 'should use ActiveModel::Errors#full_messages' do - model.errors.should_receive(:full_messages).and_call_original + expect(model.errors).to receive(:full_messages).and_call_original described_class.new(model) end it 'should translate errors using metasploit.model.invalid' do - I18n.should_receive(:translate).with( + expect(I18n).to receive(:translate).with( 'metasploit.model.errors.messages.model_invalid', hash_including( :errors => anything @@ -36,10 +34,10 @@ it 'should set translated errors as message' do message = "translated message" - I18n.stub(:translate).with('metasploit.model.errors.messages.model_invalid', anything).and_return(message) + allow(I18n).to receive(:translate).with('metasploit.model.errors.messages.model_invalid', anything).and_return(message) instance = described_class.new(model) - instance.message.should == message + expect(instance.message).to eq(message) end context '#model' do @@ -48,7 +46,7 @@ end it 'should be the passed in model' do - error_model.should == model + expect(error_model).to eq(model) end end end \ No newline at end of file diff --git a/spec/lib/metasploit/model/login/status_spec.rb b/spec/lib/metasploit/model/login/status_spec.rb index a0f924d2..6c9ff762 100644 --- a/spec/lib/metasploit/model/login/status_spec.rb +++ b/spec/lib/metasploit/model/login/status_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Login::Status do +RSpec.describe Metasploit::Model::Login::Status do context 'CONSTANTS' do context 'ALL' do subject(:all) { diff --git a/spec/lib/metasploit/model/nilify_blanks_spec.rb b/spec/lib/metasploit/model/nilify_blanks_spec.rb index 557c7338..4d5da6b4 100644 --- a/spec/lib/metasploit/model/nilify_blanks_spec.rb +++ b/spec/lib/metasploit/model/nilify_blanks_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::NilifyBlanks do +RSpec.describe Metasploit::Model::NilifyBlanks do let(:base_class) do # capture for class_eval scope described_class = self.described_class @@ -24,7 +22,7 @@ end it 'should register #nilify_blanks as a before validation callback' do - base_class.should_receive(:before_validation).with(:nilify_blanks) + expect(base_class).to receive(:before_validation).with(:nilify_blanks) # capture for class_eval scope described_class = self.described_class @@ -39,10 +37,10 @@ it 'should support adding multiple attributes' do attributes = [:a, :b] - base_class.nilify_blank *attributes + base_class.nilify_blank(*attributes) attributes.each do |attribute| - base_class.nilify_blank_attribute_set.should include(attribute) + expect(base_class.nilify_blank_attribute_set).to include(attribute) end end @@ -52,7 +50,7 @@ base_class.nilify_blank attribute base_class.nilify_blank attribute - base_class.nilify_blank_attribute_set.length.should == 1 + expect(base_class.nilify_blank_attribute_set.length).to eq(1) end end @@ -90,14 +88,14 @@ end it 'should check if value responds to blank?' do - value.should_receive(:respond_to?).with(:blank?) + expect(value).to receive(:respond_to?).with(:blank?) nilify_blanks end context 'with value responds to blank?' do it 'should call blank?' do - value.should_receive(:blank?) + expect(value).to receive(:blank?) nilify_blanks end @@ -110,7 +108,7 @@ it 'should set attribute to nil' do nilify_blanks - base_instance.blank.should be_nil + expect(base_instance.blank).to be_nil end end @@ -133,11 +131,11 @@ end before(:each) do - value.stub(:respond_to?).with(:blank?).and_return(false) + allow(value).to receive(:respond_to?).with(:blank?).and_return(false) end it 'should not call blank?' do - value.should_not_receive(:blank?) + expect(value).not_to receive(:blank?) nilify_blanks end @@ -150,7 +148,7 @@ end it 'should default to an empty Set' do - nilify_blank_attribute_set.should == Set.new + expect(nilify_blank_attribute_set).to eq(Set.new) end end end \ No newline at end of file diff --git a/spec/lib/metasploit/model/realm/key_spec.rb b/spec/lib/metasploit/model/realm/key_spec.rb index 16155864..14c10378 100644 --- a/spec/lib/metasploit/model/realm/key_spec.rb +++ b/spec/lib/metasploit/model/realm/key_spec.rb @@ -1,14 +1,12 @@ -require 'spec_helper' - -describe Metasploit::Model::Realm::Key do +RSpec.describe Metasploit::Model::Realm::Key do context 'CONSTANTS' do context 'ACTIVE_DIRECTORY_DOMAIN' do subject(:active_directory_domain) do described_class::ACTIVE_DIRECTORY_DOMAIN end - it { should == 'Active Directory Domain' } - it { should be_in described_class::ALL } + it { is_expected.to eq('Active Directory Domain') } + it { is_expected.to be_in described_class::ALL } end context 'ALL' do @@ -16,10 +14,10 @@ described_class::ALL end - it { should include described_class::ACTIVE_DIRECTORY_DOMAIN } - it { should include described_class::ORACLE_SYSTEM_IDENTIFIER } - it { should include described_class::POSTGRESQL_DATABASE } - it { should include described_class::WILDCARD } + it { is_expected.to include described_class::ACTIVE_DIRECTORY_DOMAIN } + it { is_expected.to include described_class::ORACLE_SYSTEM_IDENTIFIER } + it { is_expected.to include described_class::POSTGRESQL_DATABASE } + it { is_expected.to include described_class::WILDCARD } end context 'ORACLE_SYSTEM_IDENTIFIER' do @@ -27,8 +25,8 @@ described_class::ORACLE_SYSTEM_IDENTIFIER end - it { should == 'Oracle System Identifier' } - it { should be_in described_class::ALL } + it { is_expected.to eq('Oracle System Identifier') } + it { is_expected.to be_in described_class::ALL } end context 'POSTGRESQL DATABASE' do @@ -36,8 +34,8 @@ described_class::POSTGRESQL_DATABASE end - it { should == 'PostgreSQL Database' } - it { should be_in described_class::ALL } + it { is_expected.to eq('PostgreSQL Database') } + it { is_expected.to be_in described_class::ALL } end context 'WILDCARD' do @@ -45,20 +43,20 @@ described_class::WILDCARD end - it { should == '*' } - it { should be_in described_class::ALL } + it { is_expected.to eq('*') } + it { is_expected.to be_in described_class::ALL } end context 'SHORT_NAMES' do subject { described_class::SHORT_NAMES } it 'should have String keys' do subject.keys.each { |key| - key.should be_a(String) + expect(key).to be_a(String) } end context 'values' do subject { described_class::SHORT_NAMES.values.sort } - it { should match_array(described_class::ALL.sort) } + it { is_expected.to match_array(described_class::ALL.sort) } end end end diff --git a/spec/lib/metasploit/model/search/association/tree_spec.rb b/spec/lib/metasploit/model/search/association/tree_spec.rb index c63a0864..1a5ff22d 100644 --- a/spec/lib/metasploit/model/search/association/tree_spec.rb +++ b/spec/lib/metasploit/model/search/association/tree_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Association::Tree do +RSpec.describe Metasploit::Model::Association::Tree do context 'expand' do subject(:expand) { described_class.expand(associations) @@ -99,7 +97,7 @@ nil } - it { should be_nil } + it { is_expected.to be_nil } end context 'without nil' do @@ -311,7 +309,7 @@ nil } - it { should == [] } + it { is_expected.to eq([]) } end end diff --git a/spec/lib/metasploit/model/search/association_spec.rb b/spec/lib/metasploit/model/search/association_spec.rb index 508fbd1b..95736dcd 100644 --- a/spec/lib/metasploit/model/search/association_spec.rb +++ b/spec/lib/metasploit/model/search/association_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Association do +RSpec.describe Metasploit::Model::Search::Association do subject(:base_class) do described_class = self.described_class @@ -56,7 +54,7 @@ context 'search_associations' do subject(:search_associations) { - base_class.search_associations *associations + base_class.search_associations(*associations) } let(:associations) { diff --git a/spec/lib/metasploit/model/search/attribute_spec.rb b/spec/lib/metasploit/model/search/attribute_spec.rb index 467f3f64..0ea4d9b2 100644 --- a/spec/lib/metasploit/model/search/attribute_spec.rb +++ b/spec/lib/metasploit/model/search/attribute_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Attribute do +RSpec.describe Metasploit::Model::Search::Attribute do subject(:base_class) do described_class = self.described_class @@ -26,7 +24,7 @@ end it 'should call search_with' do - base_class.should_receive(:search_with).with( + expect(base_class).to receive(:search_with).with( Metasploit::Model::Search::Operator::Attribute, hash_including( :attribute => attribute, @@ -40,7 +38,7 @@ it 'should be in search_attribute_operator_by_attribute' do # grab operator first since it calls search_attribute and populates search_attribute_operator_by_attribute cached = operator - base_class.search_with_operator_by_name[attribute].should == cached + expect(base_class.search_with_operator_by_name[attribute]).to eq(cached) end context 'attribute' do @@ -49,7 +47,7 @@ end it 'should be the attribute passed to search_attribute' do - operator_attribute.should == attribute + expect(operator_attribute).to eq(attribute) end end @@ -59,7 +57,7 @@ end it 'should be class on which search_attribute was called' do - klass.should == base_class + expect(klass).to eq(base_class) end end @@ -69,7 +67,7 @@ end it 'should be type passed to search_attribute' do - operator_type.should == type + expect(operator_type).to eq(type) end end end diff --git a/spec/lib/metasploit/model/search/operation/value/integer_spec.rb b/spec/lib/metasploit/model/search/operation/value/integer_spec.rb index 1cc2b94e..49cb9f1f 100644 --- a/spec/lib/metasploit/model/search/operation/value/integer_spec.rb +++ b/spec/lib/metasploit/model/search/operation/value/integer_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Value::Integer do +RSpec.describe Metasploit::Model::Search::Operation::Value::Integer do it_should_behave_like 'Metasploit::Model::Search::Operation::Value::Integer' do let(:operation_class) do described_class = self.described_class diff --git a/spec/lib/metasploit/model/search/operation/value/string_spec.rb b/spec/lib/metasploit/model/search/operation/value/string_spec.rb index 73366670..ac40e90c 100644 --- a/spec/lib/metasploit/model/search/operation/value/string_spec.rb +++ b/spec/lib/metasploit/model/search/operation/value/string_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation::Value::String do +RSpec.describe Metasploit::Model::Search::Operation::Value::String do it_should_behave_like 'Metasploit::Model::Search::Operation::Value::String' do let(:operation_class) do described_class = self.described_class diff --git a/spec/lib/metasploit/model/search/operation_spec.rb b/spec/lib/metasploit/model/search/operation_spec.rb index 09eebca1..d11c29dc 100644 --- a/spec/lib/metasploit/model/search/operation_spec.rb +++ b/spec/lib/metasploit/model/search/operation_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operation do +RSpec.describe Metasploit::Model::Search::Operation do context 'parse' do subject(:parse) do described_class.parse(options) @@ -48,8 +46,8 @@ context "with at least one ':' in :formatted_operation" do before(:each) do - query.stub(:parse_operator).with(formatted_operator).and_return(operator) - operator.stub(:operate_on).with(formatted_value).and_return(operation) + allow(query).to receive(:parse_operator).with(formatted_operator).and_return(operator) + allow(operator).to receive(:operate_on).with(formatted_value).and_return(operation) end context "with multiple ':' in :formatted_operation" do @@ -58,13 +56,13 @@ end it "should treat portion before first ':' as formatted operator" do - query.should_receive(:parse_operator).with(formatted_operator) + expect(query).to receive(:parse_operator).with(formatted_operator) parse end it "should treat portion after first ':' as formatted value including later ':'" do - operator.should_receive(:operate_on).with(formatted_value) + expect(operator).to receive(:operate_on).with(formatted_value) parse end @@ -76,13 +74,13 @@ end it "should use portion before ':' as formatted operator" do - query.should_receive(:parse_operator).with(formatted_operator) + expect(query).to receive(:parse_operator).with(formatted_operator) parse end it "should use portion after ':' as formatted value" do - operator.should_receive(:operate_on).with(formatted_value) + expect(operator).to receive(:operate_on).with(formatted_value) parse end @@ -103,17 +101,17 @@ end it "should use entirety as formatted operator" do - operator.stub(:operate_on).and_return(operation) + allow(operator).to receive(:operate_on).and_return(operation) - query.should_receive(:parse_operator).with(formatted_operator).and_return(operator) + expect(query).to receive(:parse_operator).with(formatted_operator).and_return(operator) parse end it "should use '' as formatted value instead of nil" do - query.stub(:parse_operator).and_return(operator) + allow(query).to receive(:parse_operator).and_return(operator) - operator.should_receive(:operate_on).with('') + expect(operator).to receive(:operate_on).with('') parse end diff --git a/spec/lib/metasploit/model/search/operator/help_spec.rb b/spec/lib/metasploit/model/search/operator/help_spec.rb index 45e6f605..827b8843 100644 --- a/spec/lib/metasploit/model/search/operator/help_spec.rb +++ b/spec/lib/metasploit/model/search/operator/help_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::Operator::Help do +RSpec.describe Metasploit::Model::Search::Operator::Help do it_should_behave_like 'Metasploit::Model::Search::Operator::Help' do let(:operator) do operator_class.new( diff --git a/spec/lib/metasploit/model/search/with_spec.rb b/spec/lib/metasploit/model/search/with_spec.rb index ab1839df..2689a6e0 100644 --- a/spec/lib/metasploit/model/search/with_spec.rb +++ b/spec/lib/metasploit/model/search/with_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search::With do +RSpec.describe Metasploit::Model::Search::With do let(:base_class) do described_class = self.described_class @@ -37,7 +35,7 @@ end it 'should pass given options to operator_class.new' do - operator_class.should_receive(:new).with( + expect(operator_class).to receive(:new).with( hash_including(options) ).and_return(operator) @@ -45,7 +43,7 @@ end it 'should merge :klass into options passed to operator.new' do - operator_class.should_receive(:new).with( + expect(operator_class).to receive(:new).with( hash_including( :klass => base_class ) @@ -55,9 +53,9 @@ end it 'should validate operator' do - operator_class.stub(:new).and_return(operator) + allow(operator_class).to receive(:new).and_return(operator) - operator.should_receive(:valid!) + expect(operator).to receive(:valid!) search_with_operator end @@ -65,7 +63,7 @@ it 'should add operator to search_with_operator_by_name' do search_with_operator - base_class.search_with_operator_by_name[operator.name].should == operator + expect(base_class.search_with_operator_by_name[operator.name]).to eq(operator) end end @@ -75,7 +73,7 @@ end it 'should default to empty Hash' do - search_with_operator_by_name.should == {} + expect(search_with_operator_by_name).to eq({}) end end end \ No newline at end of file diff --git a/spec/lib/metasploit/model/search_spec.rb b/spec/lib/metasploit/model/search_spec.rb index 2ac425b1..09f71508 100644 --- a/spec/lib/metasploit/model/search_spec.rb +++ b/spec/lib/metasploit/model/search_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Search do +RSpec.describe Metasploit::Model::Search do subject(:base_instance) do base_class.new end @@ -16,9 +14,9 @@ base_class.send(:include, described_class) end - it { should be_a Metasploit::Model::Search::Association } - it { should be_a Metasploit::Model::Search::Attribute } - it { should be_a Metasploit::Model::Search::With } + it { is_expected.to be_a Metasploit::Model::Search::Association } + it { is_expected.to be_a Metasploit::Model::Search::Attribute } + it { is_expected.to be_a Metasploit::Model::Search::With } context 'search_operator_by_name' do subject(:search_operator_by_name) do @@ -45,7 +43,7 @@ end it 'should be same as the attribute' do - name.should == attribute + expect(name).to eq(attribute) end end end @@ -90,7 +88,7 @@ "#{association}.#{associated_attribute}".to_sym end - it { should be_a Metasploit::Model::Search::Operator::Association } + it { is_expected.to be_a Metasploit::Model::Search::Operator::Association } context 'association' do subject(:operator_association) do @@ -98,7 +96,7 @@ end it 'should be the registered association' do - operator_association.should == association + expect(operator_association).to eq(association) end end @@ -112,7 +110,7 @@ end it 'should be operator from associated class' do - source_operator.should == direct_attribute_operator + expect(source_operator).to eq(direct_attribute_operator) end end @@ -122,7 +120,7 @@ end it 'should be class that called search_operator_by_name' do - klass.should == base_class + expect(klass).to eq(base_class) end end end @@ -155,7 +153,7 @@ end it 'should be in search_operator_by_name' do - named_operator.should == operator + expect(named_operator).to eq(operator) end end end @@ -163,7 +161,7 @@ context 'without search attribute' do context 'without search association' do context 'without search with' do - it { should be_empty } + it { is_expected.to be_empty } end end end diff --git a/spec/lib/metasploit/model/spec/error_spec.rb b/spec/lib/metasploit/model/spec/error_spec.rb index 3a35c9cb..4768c876 100644 --- a/spec/lib/metasploit/model/spec/error_spec.rb +++ b/spec/lib/metasploit/model/spec/error_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - -describe Metasploit::Model::Spec::Error do - it { should be_a StandardError } +RSpec.describe Metasploit::Model::Spec::Error do + it { is_expected.to be_a StandardError } end \ No newline at end of file diff --git a/spec/lib/metasploit/model/spec/i18n_exception_handler_spec.rb b/spec/lib/metasploit/model/spec/i18n_exception_handler_spec.rb index 261d8bdd..d607d894 100644 --- a/spec/lib/metasploit/model/spec/i18n_exception_handler_spec.rb +++ b/spec/lib/metasploit/model/spec/i18n_exception_handler_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Spec::I18nExceptionHandler do +RSpec.describe Metasploit::Model::Spec::I18nExceptionHandler do subject(:i18n_exception_handler) do described_class.new end @@ -32,10 +30,10 @@ expect { call }.to raise_error(converted_exception.class) do |actual_exception| - actual_exception.class == converted_exception.class - actual_exception.key.should == converted_exception.key - actual_exception.locale.should == converted_exception.locale - actual_exception.options.should == converted_exception.options + expect(actual_exception.class).to eq(converted_exception.class) + expect(actual_exception.key).to eq(converted_exception.key) + expect(actual_exception.locale).to eq(converted_exception.locale) + expect(actual_exception.options).to eq(converted_exception.options) end end end diff --git a/spec/lib/metasploit/model/spec/pathname_collision_spec.rb b/spec/lib/metasploit/model/spec/pathname_collision_spec.rb index bbace1df..3aaefbba 100644 --- a/spec/lib/metasploit/model/spec/pathname_collision_spec.rb +++ b/spec/lib/metasploit/model/spec/pathname_collision_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Spec::PathnameCollision do +RSpec.describe Metasploit::Model::Spec::PathnameCollision do let(:pathname) do Metasploit::Model::Spec.temporary_pathname.join('pathname') end @@ -9,7 +7,7 @@ described_class.new(pathname) end - it { should be_a Metasploit::Model::Spec::Error } + it { is_expected.to be_a Metasploit::Model::Spec::Error } context 'check!' do subject(:check!) do @@ -44,11 +42,11 @@ end it 'should include pathname' do - message.should include("#{pathname} already exists.") + expect(message).to include("#{pathname} already exists.") end it 'should include potential cause' do - message.should include('Metasploit::Model::Spec.remove_temporary_pathname was not called after the previous spec.') + expect(message).to include('Metasploit::Model::Spec.remove_temporary_pathname was not called after the previous spec.') end end end diff --git a/spec/lib/metasploit/model/spec_spec.rb b/spec/lib/metasploit/model/spec_spec.rb index b24515ed..d5e13028 100644 --- a/spec/lib/metasploit/model/spec_spec.rb +++ b/spec/lib/metasploit/model/spec_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Spec do +RSpec.describe Metasploit::Model::Spec do before(:each) do @before_temporary_pathname = described_class.send(:remove_instance_variable, :@temporary_pathname) end @@ -35,11 +33,11 @@ end it 'should remove file tree' do - pathname.exist?.should be_true + expect(pathname.exist?).to eq(true) remove_temporary_pathname - pathname.exist?.should be_false + expect(pathname.exist?).to eq(false) end end @@ -82,7 +80,7 @@ end it 'should return set pathname' do - temporary_pathname.should == pathname + expect(temporary_pathname).to eq(pathname) end end @@ -107,7 +105,11 @@ expect { described_class.temporary_pathname = temporary_pathname }.to change { - described_class.instance_variable_get(:@temporary_pathname) + if described_class.instance_variable_defined? :@temporary_pathname + described_class.instance_variable_get(:@temporary_pathname) + else + nil + end }.to(temporary_pathname) end end diff --git a/spec/lib/metasploit/model/translation_spec.rb b/spec/lib/metasploit/model/translation_spec.rb index 3fd7e5e7..65597d9d 100644 --- a/spec/lib/metasploit/model/translation_spec.rb +++ b/spec/lib/metasploit/model/translation_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Translation do +RSpec.describe Metasploit::Model::Translation do let(:base_class) do described_class = self.described_class @@ -56,21 +54,21 @@ def self.model_name end it 'should have named and unnamed ancestors' do - base_class.ancestors.should include(named_class) - base_class.ancestors.should include(named_module) - base_class.ancestors.should include(unnamed_class) - base_class.ancestors.should include(unnamed_module) + expect(base_class.ancestors).to include(named_class) + expect(base_class.ancestors).to include(named_module) + expect(base_class.ancestors).to include(unnamed_class) + expect(base_class.ancestors).to include(unnamed_module) end it 'should return all ancestors that respond to model_name' do - lookup_ancestors.should include(base_class) - lookup_ancestors.should include(named_class) - lookup_ancestors.should include(named_module) + expect(lookup_ancestors).to include(base_class) + expect(lookup_ancestors).to include(named_class) + expect(lookup_ancestors).to include(named_module) end it 'should not return ancestors that do not respond to model_name' do - lookup_ancestors.should_not include(unnamed_class) - lookup_ancestors.should_not include(unnamed_module) + expect(lookup_ancestors).not_to include(unnamed_class) + expect(lookup_ancestors).not_to include(unnamed_module) end end diff --git a/spec/lib/metasploit/model/version_spec.rb b/spec/lib/metasploit/model/version_spec.rb index 312da102..6c534ab6 100644 --- a/spec/lib/metasploit/model/version_spec.rb +++ b/spec/lib/metasploit/model/version_spec.rb @@ -1,141 +1,3 @@ -require 'spec_helper' - -describe Metasploit::Model::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 - branch_regex = /\A(?bug|chore|feature|staging)(\/(?[^\/]+))?\/(?[^\/]+)\z/ - match = branch.match(branch_regex) - - if match - it 'matches the branch relative name' do - expect(prerelease).to eq(match[:prerelease]) - end - else - tag_regex = /\Av(?\d+).(?\d+).(?\d+)(\.pre\.(?.*))?\z/ - # travis-ci sets TRAVIS_BRANCH to the tag name for tag builds - match = branch.match(tag_regex) - - if match - tag_prerelease = match[:prerelease] - - if tag_prerelease - it 'matches the tag prerelease converted from a gem version to a VERSION' do - expect(prerelease).to eq(tag_prerelease.gsub('.pre.', '-')) - end - else - it 'does not have a PRERELEASE' do - expect(defined? described_class::PRERELEASE).to be_nil - end - 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 - 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 +RSpec.describe Metasploit::Model::Version do + it_should_behave_like 'Metasploit::Version Version Module' +end diff --git a/spec/lib/metasploit/model/visitation/visit_spec.rb b/spec/lib/metasploit/model/visitation/visit_spec.rb index 5817253e..2aad42ff 100644 --- a/spec/lib/metasploit/model/visitation/visit_spec.rb +++ b/spec/lib/metasploit/model/visitation/visit_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe Metasploit::Model::Visitation::Visit do +RSpec.describe Metasploit::Model::Visitation::Visit do let(:base_class) do described_class = self.described_class @@ -54,15 +52,15 @@ end it 'should return Array(Metasploit::Model::Visitation::Visitor)' do - visit.should be_an Array - visit.length.should == 1 - visit.first.should be_a Metasploit::Model::Visitation::Visitor + expect(visit).to be_an Array + expect(visit.length).to eq(1) + expect(visit.first).to be_a Metasploit::Model::Visitation::Visitor end it 'should add Metasploit::Model::Visitation::Visitor to visitor_by_module_name' do visitor = visit.first - base_class.visitor_by_module_name[mod.name].should == visitor + expect(base_class.visitor_by_module_name[mod.name]).to eq(visitor) end end @@ -88,18 +86,22 @@ end it 'should return Array' do - visit.should be_an Array - visit.length.should == module_names.length - - visit.all? { |visitor| - visitor.is_a? Metasploit::Model::Visitation::Visitor - }.should be_true + expect(visit).to be_an Array + expect(visit.length).to eq(module_names.length) + + expect( + visit.all? { |visitor| + visitor.is_a? Metasploit::Model::Visitation::Visitor + } + ).to eq(true) end it 'should each Metasploit::Model::Visitation::Visitor to visitor_by_module_name' do - module_names.all? { |module_name| - visit.include? base_class.visitor_by_module_name[module_name] - }.should be_true + expect( + module_names.all? { |module_name| + visit.include? base_class.visitor_by_module_name[module_name] + } + ).to eq(true) end end end @@ -158,7 +160,7 @@ end it 'should return visitor from visitor_by_module' do - visitor.should == klass_visitor + expect(visitor).to eq(klass_visitor) end end @@ -187,13 +189,13 @@ end it 'should return ancestor visitor' do - visitor.should == ancestor_visitor + expect(visitor).to eq(ancestor_visitor) end it 'should cache ancestor visitor as visitor for klass in visitor_by_module' do visitor - base_class.visitor_by_module[klass].should == ancestor_visitor + expect(base_class.visitor_by_module[klass]).to eq(ancestor_visitor) end end @@ -203,13 +205,13 @@ end it 'should return ancestor visitor' do - visitor.should == ancestor_visitor + expect(visitor).to eq(ancestor_visitor) end it 'should cache ancestor visitor as visitor for klass in visitor_by_module' do visitor - base_class.visitor_by_module[klass].should == ancestor_visitor + expect(base_class.visitor_by_module[klass]).to eq(ancestor_visitor) end end @@ -229,7 +231,7 @@ end it 'should default to empty Hash' do - visitor_by_module.should == {} + expect(visitor_by_module).to eq({}) end end @@ -239,7 +241,7 @@ end it 'should default to empty Hash' do - visitor_by_module_name.should == {} + expect(visitor_by_module_name).to eq({}) end end @@ -274,13 +276,13 @@ end it 'should find visitor for node.class' do - base_class.should_receive(:visitor).with(node.class).and_call_original + expect(base_class).to receive(:visitor).with(node.class).and_call_original visit end it 'should visit on visitor' do - @visitor.should_receive(:visit).with(base_instance, node) + expect(@visitor).to receive(:visit).with(base_instance, node) visit end @@ -309,7 +311,7 @@ end it "should be able to call visit from inside a visitor's block" do - visit.should == leaf_node + expect(visit).to eq(leaf_node) end end end diff --git a/spec/lib/metasploit/model_spec.rb b/spec/lib/metasploit/model_spec.rb new file mode 100644 index 00000000..acf778af --- /dev/null +++ b/spec/lib/metasploit/model_spec.rb @@ -0,0 +1,4 @@ +RSpec.describe Metasploit::Model do + it_should_behave_like 'Metasploit::Version GEM_VERSION constant' + it_should_behave_like 'Metasploit::Version VERSION constant' +end diff --git a/spec/matchers/validate_nilness_of_spec.rb b/spec/matchers/validate_nilness_of_spec.rb index 7db982e0..a298cf9c 100644 --- a/spec/matchers/validate_nilness_of_spec.rb +++ b/spec/matchers/validate_nilness_of_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - RSpec.describe 'validate_nilness_of' do let(:record) { record_class.new diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb old mode 100755 new mode 100644 index eaf84c54..4d8e7fa9 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,22 +14,95 @@ require File.expand_path('../dummy/config/environment.rb', __FILE__) require 'rspec/rails' -require 'rspec/autorun' -# full backtrace in logs so its easier to trace errors -Rails.backtrace_cleaner.remove_silencers! +# 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 -spec_pathname = Metasploit::Model::Engine.root.join('spec') +roots = [ + Metasploit::Model::Engine.root.to_path, + gem_specification.gem_dir +] -Dir[spec_pathname.join('support', '**', '*.rb')].each do |f| - require f +roots.each do |root| + Dir[File.join(root, 'spec', 'support', '**', '*.rb')].each do |f| + require f + end end +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 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 + + # 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 + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax + # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching + 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 = 10 + + # 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 + config.before(:suite) do # this must be explicitly set here because it should always be spec/tmp for w/e project is using # Metasploit::Model::Spec to handle file system clean up. - Metasploit::Model::Spec.temporary_pathname = spec_pathname.join('tmp') + Metasploit::Model::Spec.temporary_pathname = Metasploit::Model::Engine.root.join('spec', 'tmp') # Clean up any left over files from a previously aborted suite Metasploit::Model::Spec.remove_temporary_pathname @@ -40,7 +113,4 @@ config.after(:each) do Metasploit::Model::Spec.remove_temporary_pathname end - - config.mock_with :rspec - config.order = :random end diff --git a/spec/support/shared/contexts/metasploit/model/search/operator/union/children.rb b/spec/support/shared/contexts/metasploit/model/search/operator/union/children.rb index f1be1c67..15fe10c2 100644 --- a/spec/support/shared/contexts/metasploit/model/search/operator/union/children.rb +++ b/spec/support/shared/contexts/metasploit/model/search/operator/union/children.rb @@ -1,4 +1,4 @@ -shared_context 'Metasploit::Model::Search::Operator::Group::Union#children' do +RSpec.shared_context 'Metasploit::Model::Search::Operator::Group::Union#children' do subject(:children) do operator.children(formatted_value) end diff --git a/spec/support/shared/examples/metasploit/model/search/operation/value/integer.rb b/spec/support/shared/examples/metasploit/model/search/operation/value/integer.rb index c9450e57..771b3bb0 100644 --- a/spec/support/shared/examples/metasploit/model/search/operation/value/integer.rb +++ b/spec/support/shared/examples/metasploit/model/search/operation/value/integer.rb @@ -1,4 +1,4 @@ -shared_examples_for 'Metasploit::Model::Search::Operation::Value::Integer' do +RSpec.shared_examples_for 'Metasploit::Model::Search::Operation::Value::Integer' do let(:operation_class) do described_class end @@ -8,7 +8,7 @@ operation_class end - it { should include Metasploit::Model::Search::Operation::Value::Integer } + it { is_expected.to include Metasploit::Model::Search::Operation::Value::Integer } end context '#value' do @@ -26,7 +26,7 @@ end it 'should pass through Integer' do - value.should == formatted_value + expect(value).to eq(formatted_value) end end @@ -40,7 +40,7 @@ end it 'should convert String to Integer' do - value.should == integer + expect(value).to eq(integer) end end @@ -54,11 +54,11 @@ end it 'should not extract the number' do - value.should_not == integer + expect(value).not_to eq(integer) end it 'should pass through the full value' do - value.should == formatted_value + expect(value).to eq(formatted_value) end end @@ -68,11 +68,11 @@ end it 'should not truncate Float to Integer' do - value.should_not == formatted_value.to_i + expect(value).not_to eq(formatted_value.to_i) end it 'should pass through Float' do - value.should == formatted_value + expect(value).to eq(formatted_value) end end end diff --git a/spec/support/shared/examples/metasploit/model/search/operation/value/string.rb b/spec/support/shared/examples/metasploit/model/search/operation/value/string.rb index 86a0ba5e..1eba1987 100644 --- a/spec/support/shared/examples/metasploit/model/search/operation/value/string.rb +++ b/spec/support/shared/examples/metasploit/model/search/operation/value/string.rb @@ -1,4 +1,4 @@ -shared_examples_for 'Metasploit::Model::Search::Operation::Value::String' do +RSpec.shared_examples_for 'Metasploit::Model::Search::Operation::Value::String' do let(:operation_class) do described_class end @@ -8,7 +8,7 @@ operation_class end - it { should include Metasploit::Model::Search::Operation::Value::String } + it { is_expected.to include Metasploit::Model::Search::Operation::Value::String } end context '#value' do @@ -26,7 +26,7 @@ end it 'should convert to String' do - value.should == '5' + expect(value).to eq('5') end end @@ -36,7 +36,7 @@ end it 'should pass through String' do - value.should == formatted_value + expect(value).to eq(formatted_value) end end @@ -46,7 +46,7 @@ end it 'should convert to String' do - value.should == 'a_symbol' + expect(value).to eq('a_symbol') end end end diff --git a/spec/support/shared/examples/metasploit/model/search/operator/help.rb b/spec/support/shared/examples/metasploit/model/search/operator/help.rb index b7c93e40..3d9a9aa0 100644 --- a/spec/support/shared/examples/metasploit/model/search/operator/help.rb +++ b/spec/support/shared/examples/metasploit/model/search/operator/help.rb @@ -1,4 +1,4 @@ -shared_examples_for 'Metasploit::Model::Search::Operator::Help' do +RSpec.shared_examples_for 'Metasploit::Model::Search::Operator::Help' do context '#help' do subject(:help) do operator.help @@ -24,7 +24,7 @@ # klass needs to be named or model_name will fail. stub_const('Klass', klass) # since missing translations raise exceptions, and there is no translation for klass, have to stub out. - klass.model_name.stub(:human).and_return(model) + allow(klass.model_name).to receive(:human).and_return(model) backend = I18n.backend @@ -59,31 +59,31 @@ end it 'should use #klass #i18n_scope to lookup translations specific to the #klass or one of its ancestors' do - klass.should_receive(:i18n_scope).and_call_original + expect(klass).to receive(:i18n_scope).and_call_original help end it 'should lookup ancestors of #klass to find translations specific to #klass or its ancestors' do - klass.should_receive(:lookup_ancestors).and_call_original + expect(klass).to receive(:lookup_ancestors).and_call_original help end it 'should use #class #i18n_scope to lookup translations specific to the operator class or one of its ancestors' do - operator.class.should_receive(:i18n_scope) + expect(operator.class).to receive(:i18n_scope) help end it 'should lookup ancestors of the operator class to find translations specific to the operator class or one of its ancestors' do - operator.class.should_receive(:lookup_ancestors).and_return([]) + expect(operator.class).to receive(:lookup_ancestors).and_return([]) help end it "should pass #klass translation key for operator with the given name as the primary translation key" do - I18n.should_receive(:translate).with( + expect(I18n).to receive(:translate).with( :"#{klass.i18n_scope}.ancestors.#{klass.model_name.i18n_key}.search.operator.names.#{name}.help", anything ) @@ -92,23 +92,25 @@ end it 'should pass other translation keys as default option' do - I18n.should_receive(:translate) do |_key, options| - options.should be_a Hash + expect(I18n).to receive(:translate) do |_key, options| + expect(options).to be_a Hash default = options[:default] - default.should be_an Array + expect(default).to be_an Array - default.all? { |key| - key.is_a? Symbol - }.should be_true + expect( + default.all? { |key| + key.is_a? Symbol + } + ).to eq(true) end help end it 'should pass #name of operator as name option' do - I18n.should_receive(:translate).with( + expect(I18n).to receive(:translate).with( anything, hash_including(name: name) ) @@ -117,7 +119,7 @@ end it 'should pass the human model name of #klass as model option' do - I18n.should_receive(:translate).with( + expect(I18n).to receive(:translate).with( anything, hash_including(model: klass.model_name.human) ) @@ -126,7 +128,7 @@ end it 'should be translated correctly' do - help.should == help_template % { model: model, name: name } + expect(help).to eq(help_template % { model: model, name: name }) end end end \ No newline at end of file diff --git a/spec/support/shared/examples/metasploit/model/translation.rb b/spec/support/shared/examples/metasploit/model/translation.rb index aca27ba9..06161bfc 100644 --- a/spec/support/shared/examples/metasploit/model/translation.rb +++ b/spec/support/shared/examples/metasploit/model/translation.rb @@ -1,4 +1,4 @@ -shared_examples_for 'Metasploit::Model::Translation' do |options={}| +RSpec.shared_examples_for 'Metasploit::Model::Translation' do |options={}| options.assert_valid_keys(:metasploit_model_ancestor) metasploit_model_ancestor = options.fetch(:metasploit_model_ancestor) @@ -14,7 +14,7 @@ metasploit_model_ancestor.instance_variable_get :@_dependencies end - it { should include Metasploit::Model::Translation } + it { is_expected.to include Metasploit::Model::Translation } end end end @@ -24,7 +24,7 @@ base_class.i18n_scope end - it { should == 'metasploit.model' } + it { is_expected.to eq('metasploit.model') } end context 'lookup_ancestors' do @@ -32,6 +32,6 @@ base_class.lookup_ancestors end - it { should include metasploit_model_ancestor } + it { is_expected.to include metasploit_model_ancestor } end end \ No newline at end of file diff --git a/spec/support/shared/examples/search/query.rb b/spec/support/shared/examples/search/query.rb index 7c8b9173..6a8eee96 100644 --- a/spec/support/shared/examples/search/query.rb +++ b/spec/support/shared/examples/search/query.rb @@ -1,4 +1,4 @@ -shared_examples_for 'search query' do |options={}| +RSpec.shared_examples_for 'search query' do |options={}| options.assert_valid_keys(:formatted_operator) formatted_operator = options.fetch(:formatted_operator) @@ -35,8 +35,8 @@ } end - it { should_not be_nil } - it { should be_valid } + it { is_expected.not_to be_nil } + it { is_expected.to be_valid } end end end diff --git a/spec/support/shared/examples/search_association.rb b/spec/support/shared/examples/search_association.rb index c84c5786..4ad9d434 100644 --- a/spec/support/shared/examples/search_association.rb +++ b/spec/support/shared/examples/search_association.rb @@ -1,4 +1,4 @@ -shared_examples_for 'search_association' do |association| +RSpec.shared_examples_for 'search_association' do |association| context association do let(:association_operators) do base_class.search_operator_by_name.select { |_name, operator| diff --git a/spec/support/shared/examples/search_attribute.rb b/spec/support/shared/examples/search_attribute.rb index ccb53e67..836ae18a 100644 --- a/spec/support/shared/examples/search_attribute.rb +++ b/spec/support/shared/examples/search_attribute.rb @@ -1,4 +1,4 @@ -shared_examples_for 'search_attribute' do |name, options={}| +RSpec.shared_examples_for 'search_attribute' do |name, options={}| options.assert_valid_keys(:type) type = options.fetch(:type) @@ -19,8 +19,8 @@ base_class.send(attribute_set_method_name) end - it { should be_a Set } - it { should_not be_empty } + it { is_expected.to be_a Set } + it { is_expected.not_to be_empty } end end end diff --git a/spec/support/shared/examples/search_with.rb b/spec/support/shared/examples/search_with.rb index baf9f9c2..177d9001 100644 --- a/spec/support/shared/examples/search_with.rb +++ b/spec/support/shared/examples/search_with.rb @@ -1,4 +1,4 @@ -shared_examples_for 'search_with' do |operation_class, options={}| +RSpec.shared_examples_for 'search_with' do |operation_class, options={}| name = options.fetch(:name) context name do @@ -6,7 +6,7 @@ base_class.search_with_operator_by_name[name] end - it { should be_a operation_class } + it { is_expected.to be_a operation_class } options.each do |key, value| # skip :name since it use used to look up operator, so it's already been checked or with_operator would be `nil`