Skip to content

Commit

Permalink
Added RSpec examples to test model_file and model_name.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Feb 4, 2024
1 parent e044d89 commit 1b34ae5
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec/cli/commands/asn_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/asn'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::Asn do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/certs_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/certs'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::Certs do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/creds_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/creds'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::Creds do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/emails_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/emails'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::Emails do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/hosts_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/hosts'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::Hosts do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/ips_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/ips'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::Ips do
include_examples "man_page"
include_examples "ModelCommand"
end
35 changes: 35 additions & 0 deletions spec/cli/commands/model_command_examples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'rspec'

RSpec.shared_examples_for "ModelCommand" do
describe "model_file" do
subject { described_class }

it "must define a model_file" do
expect(subject.model_file).to be_kind_of(String)
expect(subject.model_file).to match(%r{\Aronin/db/[a-z0-9_]+\z})
end

it "must be a requirable file" do
expect {
require subject.model_file
}.to_not raise_error
end
end

describe "model_name" do
subject { described_class }

it "must define a model_name" do
expect(subject.model_name).to be_kind_of(String)
expect(subject.model_name).to match(/\A[A-Z][A-Za-z0-9]+\z/)
end

it "must be a valid constant within Ronin::DB" do
expect(Ronin::DB.const_defined?(subject.model_name)).to be(true)
end

it "must be a kind of ActiveRecord::Base class" do
expect(Ronin::DB.const_get(subject.model_name)).to be < ActiveRecord::Base
end
end
end
2 changes: 2 additions & 0 deletions spec/cli/commands/open_ports_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/open_ports'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::OpenPorts do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/oses_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/oses'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::Oses do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/passwords_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/passwords'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::Passwords do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/people_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/people'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::People do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/phone_numbers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/phone_numbers'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::PhoneNumbers do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/ports_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/ports'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::Ports do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/services_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/services'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::Services do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/software_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/software'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::Software do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/street_addresses_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/street_addresses'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::StreetAddresses do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/urls_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'
require 'ronin/db/cli/commands/urls'
require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::Urls do
include_examples "man_page"
include_examples "ModelCommand"
end
2 changes: 2 additions & 0 deletions spec/cli/commands/web_vulns_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
require 'ronin/db/url'

require_relative 'man_page_example'
require_relative 'model_command_examples'

describe Ronin::DB::CLI::Commands::WebVulns do
include_examples "man_page"
include_examples "ModelCommand"

let(:url) { Ronin::DB::URL.import('https://example.com/page.php?id=1') }

Expand Down

0 comments on commit 1b34ae5

Please sign in to comment.