[rspec-users] rspec model testing - test on user defined validation- How do I test that the create failed.

Pat Maddox pergesu at gmail.com
Fri Jan 16 16:28:35 EST 2009


On Fri, Jan 16, 2009 at 8:51 AM, Wegener Ken <kgwcoach at yahoo.com> wrote:
> Solved my problem  all the examples I could find had the following example
> myTest.should_not_be_valid
> but that method wasn't a valid method.
>
> It appears the method has been refactored and the new form is
> mytest.should_not(be_valid)  which does work
>
> following test does what I want
> it "should not create a new instance given incompatible attribute values" do
>
> @invalid_attributes1 = {
>    :field1 = "value for field1"
>    :field2 = "value for field2"
>   }
>
> mytest = MyTest.create(@invalid_attributes)
> mytest.should_not(be_valid)
> end

Correct.  You can also write
mytest.should_not be_valid

which is a bit prettier :)

Pat


More information about the rspec-users mailing list