-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
a78c2f2
commit 99adcef
Showing
12 changed files
with
212 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.