Skip to content

Commit

Permalink
feat: Minitest replaces RSpec (#57)
Browse files Browse the repository at this point in the history
* feat: Adding Minitest and moving tests over from Rspec

* Port entity_spec to entity_test

* Porting obj_spec to obj_test

* Removing RSpec

* Update Gemfile.lock

* Update obvious.yml

* fix: Make the tests green post master merge

* chore: Clean up tests to match minitest style

* Update entity_test.rb
  • Loading branch information
brianknapp authored Jan 31, 2022
1 parent a78c2f2 commit 99adcef
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 233 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/obvious.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: |
bundle exec rspec
ruby -Ilib:test test/*_test.rb
15 changes: 0 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ PATH
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.5.0)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.3)

PLATFORMS
ruby
Expand All @@ -28,7 +14,6 @@ PLATFORMS

DEPENDENCIES
obvious!
rspec

BUNDLED WITH
2.3.4
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
require "bundler/gem_tasks"
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList['test/**/*_test.rb']
end
task :default => :test
2 changes: 0 additions & 2 deletions obvious.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ Gem::Specification.new do |gem|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]

gem.add_development_dependency "rspec"
end
Binary file removed spec/.spec_helper.rb.swp
Binary file not shown.
63 changes: 0 additions & 63 deletions spec/contract_spec.rb

This file was deleted.

75 changes: 0 additions & 75 deletions spec/entity_spec.rb

This file was deleted.

74 changes: 0 additions & 74 deletions spec/obj_spec.rb

This file was deleted.

3 changes: 0 additions & 3 deletions spec/spec_helper.rb

This file was deleted.

62 changes: 62 additions & 0 deletions test/contract_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'minitest/autorun'
require_relative '../lib/obvious/contract'

class TestContract < Obvious::Contract
contract_for :test, {
input: { id: Integer },
output: { id: Integer, value: String }
}

def test input
{ id: 1, value: 'this is a test' }
end
end

class ContractTest < Minitest::Test
def test_valid_input
result = TestContract.new.test(id: 1)
assert_equal({id: 1, value: 'this is a test'}, result)
end

def test_invalid_input
assert_raises Obvious::ContractInputError do
TestContract.new.test(Hash.new)
end
end

def test_empty_hash_return
assert_raises Obvious::DataNotFoundError do
tc = TestContract.new
tc.stub :test_alias, {} do
tc.test(id: 1)
end
end
end

def test_nil_return
assert_raises Obvious::ContractOutputError do
tc = TestContract.new
tc.stub :test_alias, nil do
tc.test(id: 1)
end
end
end
end

class HashTest < Minitest::Test
def test_valid_has_shape
assert({id: 1}.has_shape?(id: Integer))
end

def test_invalid_has_shape
refute({id: 1}.has_shape?(id: String))
end

def test_has_shape_allow_nil_values
assert({id: nil}.has_shape?({id: String}))
end

def test_has_shape_return_invalid_field
assert_equal([false, :id], { id: 1 }.has_shape?({id: String}, true))
end
end
Loading

0 comments on commit 99adcef

Please sign in to comment.