Refactor raise_error(specific_error) expectation (#4912)

* Refactor raise_error(specific_error) expectation

The full RSpec warining is
```
WARNING: Using `expect { }.not_to raise_error(SpecificErrorClass)` risks false positives,
since literally any other error would cause the expectation to pass,
including those raised by Ruby (e.g. NoMethodError, NameError and ArgumentError),
meaning the code you are intending to test may not even get reached.
Instead consider using `expect { }.not_to raise_error` or `expect { }.to raise_error(DifferentSpecificErrorClass)`.
```

* Refactor jsitor tests to test behaviour

As pointed out by @rhymes, the previous tests were not
testing actual behaviour. This is an attempt at improving the tests.
This commit is contained in:
Anthony Musyoki 2019-11-26 16:46:33 +03:00 committed by Ben Halpern
parent 7d0aeeefe5
commit 2537670968
3 changed files with 34 additions and 20 deletions

View file

@ -26,45 +26,45 @@ RSpec.describe JsitorTag, type: :liquid_tag do
end
it "parses the link with spaces before and after" do
link = " https://jsitor.com/embed/1QgJVmCam "
expect do
create_jsitor_liquid_tag(link)
end.not_to raise_error(StandardError)
link = " https://jsitor.com/embed/B7FQ5tHbY "
liquid = create_jsitor_liquid_tag(link)
render_jsitor_iframe = liquid.render
Approvals.verify(render_jsitor_iframe, name: "jsitor_liquid_tag", format: :html)
end
it "accepts jsitor link with query params" do
link = "https://jsitor.com/embed/1QgJVmCam?html&css"
expect do
create_jsitor_liquid_tag(link)
end.not_to raise_error(StandardError)
link = "https://jsitor.com/embed/B7FQ5tHbY?html&css"
liquid = create_jsitor_liquid_tag(link)
render_jsitor_iframe = liquid.render
Approvals.verify(render_jsitor_iframe, name: "jsitor_liquid_tag_with_params", format: :html)
end
it "accepts jsitor id" do
link = "B7FQ5tHbY"
expect do
create_jsitor_liquid_tag(link)
end.not_to raise_error(StandardError)
liquid = create_jsitor_liquid_tag(link)
render_jsitor_iframe = liquid.render
Approvals.verify(render_jsitor_iframe, name: "jsitor_liquid_tag", format: :html)
end
it "accepts jsitor id with parameters" do
link = "B7FQ5tHbY?html&css"
expect do
create_jsitor_liquid_tag(link)
end.not_to raise_error(StandardError)
liquid = create_jsitor_liquid_tag(link)
render_jsitor_iframe = liquid.render
Approvals.verify(render_jsitor_iframe, name: "jsitor_liquid_tag_with_params", format: :html)
end
it "accepts jsitor link with hyphen id" do
link = "https://jsitor.com/embed/2o-syYxmi"
expect do
create_jsitor_liquid_tag(link)
end.not_to raise_error(StandardError)
liquid = create_jsitor_liquid_tag(link)
render_jsitor_iframe = liquid.render
Approvals.verify(render_jsitor_iframe, name: "jsitor_liquid_tag_with_hyphen", format: :html)
end
it "accepts jsitor id with hyphen" do
link = "2o-syYxmi"
expect do
create_jsitor_liquid_tag(link)
end.not_to raise_error(StandardError)
liquid = create_jsitor_liquid_tag(link)
render_jsitor_iframe = liquid.render
Approvals.verify(render_jsitor_iframe, name: "jsitor_liquid_tag_with_hyphen", format: :html)
end
it "doesnt accepts jsitor link with a / at the end" do

View file

@ -0,0 +1,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<iframe height="400" src="https://jsitor.com/embed/2o-syYxmi" scrolling="no" frameborder="no" loading="lazy" allowtransparency="true" style="width: 100%;">
</iframe>
</body>
</html>

View file

@ -0,0 +1,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<iframe height="400" src="https://jsitor.com/embed/B7FQ5tHbY?html&amp;css" scrolling="no" frameborder="no" loading="lazy" allowtransparency="true" style="width: 100%;">
</iframe>
</body>
</html>