diff --git a/CHANGELOG.md b/CHANGELOG.md index 52abaed..2b91028 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/minitest_to_rspec/input/subprocessors/call.rb b/lib/minitest_to_rspec/input/subprocessors/call.rb index f3604ee..0240f7f 100644 --- a/lib/minitest_to_rspec/input/subprocessors/call.rb +++ b/lib/minitest_to_rspec/input/subprocessors/call.rb @@ -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 @@ -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) diff --git a/spec/fixtures/29_assert_empty/in.rb b/spec/fixtures/29_assert_empty/in.rb new file mode 100644 index 0000000..d920e21 --- /dev/null +++ b/spec/fixtures/29_assert_empty/in.rb @@ -0,0 +1,2 @@ +assert_empty(Banana.new) +assert_empty(Banana.new, "Expected empty banana skin but got delicious content") diff --git a/spec/fixtures/29_assert_empty/out.rb b/spec/fixtures/29_assert_empty/out.rb new file mode 100644 index 0000000..02f4bc3 --- /dev/null +++ b/spec/fixtures/29_assert_empty/out.rb @@ -0,0 +1,2 @@ +expect(Banana.new).to(be_empty) +expect(Banana.new).to(be_empty) diff --git a/spec/fixtures/30_assert_kind_of/in.rb b/spec/fixtures/30_assert_kind_of/in.rb new file mode 100644 index 0000000..f442d35 --- /dev/null +++ b/spec/fixtures/30_assert_kind_of/in.rb @@ -0,0 +1,2 @@ +assert_kind_of(Banana, Banana.new) +assert_kind_of(Banana, Banana.new, "Expected Banana to be a kind of Banana") diff --git a/spec/fixtures/30_assert_kind_of/out.rb b/spec/fixtures/30_assert_kind_of/out.rb new file mode 100644 index 0000000..69b7c97 --- /dev/null +++ b/spec/fixtures/30_assert_kind_of/out.rb @@ -0,0 +1,2 @@ +expect(Banana.new).to(be_a(Banana)) +expect(Banana.new).to(be_a(Banana)) diff --git a/spec/fixtures/31_assert_instance_of/in.rb b/spec/fixtures/31_assert_instance_of/in.rb new file mode 100644 index 0000000..e2e82e1 --- /dev/null +++ b/spec/fixtures/31_assert_instance_of/in.rb @@ -0,0 +1,2 @@ +assert_instance_of(Banana, Banana.new) +assert_instance_of(Banana, Banana.new, "Expected Banana to be an actual Banana") diff --git a/spec/fixtures/31_assert_instance_of/out.rb b/spec/fixtures/31_assert_instance_of/out.rb new file mode 100644 index 0000000..3249100 --- /dev/null +++ b/spec/fixtures/31_assert_instance_of/out.rb @@ -0,0 +1,2 @@ +expect(Banana.new).to(be_instance_of(Banana)) +expect(Banana.new).to(be_instance_of(Banana))