rspec

Ruby, rspec Expect error when testing method

走远了吗. 提交于 2020-12-12 11:20:08
问题 I have a method that looks like build_object(arg1, arg2, arg3, arg4, arg5) I want to test this method when a certain value is passed for arg5. I am trying something like expect(my_method(p1, p2, p3, p4, bad5)).to raise_error(ArgumentError) I get the following error: ArgumentError: The expect syntax does not support operator matchers, so you must pass a matcher to `#to`. I am very new to Ruby and rspec testing, so any help is appreciated. Please explain what your answer is doing so that I

Is there an rspec test for exact length of an attribute?

寵の児 提交于 2020-12-04 17:27:17
问题 I'm trying to test the length of a zip code attribute to ensure its 5 characters long. Right now I'm testing to make sure its not blank and then too short with 4 characters and too long with 6 characters. Is there a way to test it being exactly 5 characters? So far I've found nothing online or in the rspec book. 回答1: If you're testing a validation on an ActiveRecord model, I recommend trying out shoulda-matchers . It provides a bunch of useful RSpec extensions useful for Rails. You could

Is there an rspec test for exact length of an attribute?

半城伤御伤魂 提交于 2020-12-04 17:25:57
问题 I'm trying to test the length of a zip code attribute to ensure its 5 characters long. Right now I'm testing to make sure its not blank and then too short with 4 characters and too long with 6 characters. Is there a way to test it being exactly 5 characters? So far I've found nothing online or in the rspec book. 回答1: If you're testing a validation on an ActiveRecord model, I recommend trying out shoulda-matchers . It provides a bunch of useful RSpec extensions useful for Rails. You could

Is there an rspec test for exact length of an attribute?

孤街醉人 提交于 2020-12-04 17:24:19
问题 I'm trying to test the length of a zip code attribute to ensure its 5 characters long. Right now I'm testing to make sure its not blank and then too short with 4 characters and too long with 6 characters. Is there a way to test it being exactly 5 characters? So far I've found nothing online or in the rspec book. 回答1: If you're testing a validation on an ActiveRecord model, I recommend trying out shoulda-matchers . It provides a bunch of useful RSpec extensions useful for Rails. You could

Is there an rspec test for exact length of an attribute?

浪尽此生 提交于 2020-12-04 17:21:07
问题 I'm trying to test the length of a zip code attribute to ensure its 5 characters long. Right now I'm testing to make sure its not blank and then too short with 4 characters and too long with 6 characters. Is there a way to test it being exactly 5 characters? So far I've found nothing online or in the rspec book. 回答1: If you're testing a validation on an ActiveRecord model, I recommend trying out shoulda-matchers . It provides a bunch of useful RSpec extensions useful for Rails. You could