Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support assert_empty, assert_kind_of, assert_instance_of #25

Merged
merged 1 commit into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ of [keepachangelog.com][2].

### Added

- None
- [#25](https://github.com/jaredbeck/minitest_to_rspec/pull/25) -
Support `assert_empty`, `assert_kind_of`, `assert_instance_of`

### Fixed

Expand Down
28 changes: 28 additions & 0 deletions lib/minitest_to_rspec/input/subprocessors/call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,22 @@ def be_nil
matcher(:be_nil)
end

def be_empty
matcher(:be_empty)
end

def be_truthy
matcher(:be_truthy)
end

def be_a(exp)
matcher(:be_a, exp)
end

def be_instance_of(exp)
matcher(:be_instance_of, exp)
end

def call_to_question_mark?(exp)
sexp_type?(:call, exp) && Model::Call.new(exp).question_mark_method?
end
Expand Down Expand Up @@ -95,12 +107,28 @@ def method_assert_not_nil
expect_to_not(be_nil, @exp.arguments[0], true)
end

def method_assert_empty
expect_to(be_empty, @exp.arguments[0], true)
end

def method_assert_not_equal
expected = @exp.arguments[0]
calculated = @exp.arguments[1]
expect_to_not(eq(expected), calculated, true)
end

def method_assert_kind_of
expected = @exp.arguments[0]
calculated = @exp.arguments[1]
expect_to(be_a(expected), calculated, true)
end

def method_assert_instance_of
expected = @exp.arguments[0]
calculated = @exp.arguments[1]
expect_to(be_instance_of(expected), calculated, true)
end

def method_expects
if @exp.num_arguments == 1 &&
%i[lit hash].include?(@exp.arguments.first.sexp_type)
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/29_assert_empty/in.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
assert_empty(Banana.new)
assert_empty(Banana.new, "Expected empty banana skin but got delicious content")
2 changes: 2 additions & 0 deletions spec/fixtures/29_assert_empty/out.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
expect(Banana.new).to(be_empty)
expect(Banana.new).to(be_empty)
2 changes: 2 additions & 0 deletions spec/fixtures/30_assert_kind_of/in.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
assert_kind_of(Banana, Banana.new)
assert_kind_of(Banana, Banana.new, "Expected Banana to be a kind of Banana")
2 changes: 2 additions & 0 deletions spec/fixtures/30_assert_kind_of/out.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
expect(Banana.new).to(be_a(Banana))
expect(Banana.new).to(be_a(Banana))
2 changes: 2 additions & 0 deletions spec/fixtures/31_assert_instance_of/in.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
assert_instance_of(Banana, Banana.new)
assert_instance_of(Banana, Banana.new, "Expected Banana to be an actual Banana")
2 changes: 2 additions & 0 deletions spec/fixtures/31_assert_instance_of/out.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
expect(Banana.new).to(be_instance_of(Banana))
expect(Banana.new).to(be_instance_of(Banana))