I made this changes and still it fails.
I also see this message :
Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
Roelof
Op dinsdag 9 december 2014 17:43:24 UTC+1 schreef Myron Marston:
> On Tuesday, December 9, 2014 8:14:34 AM UTC-8, Roelof Wobben wrote:
>>
>> Hello,
>>
>> I have this model :
>>
>> class Product < ActiveRecord::Base
>> validates :title, :description, :image_url, presence: true
>> validates :price, numericality: {greater_than_or_equal_to: 0.01}
>> validates :title, uniqueness: true
>> validates :image_url, allow_blank: true,
>> format: { with: %r{\.(gif|jpg|png)\Z}i,
>> message: 'must be a URL for GIF, JPG or PNG image.'
>> }
>> end
>>
>> So I have made this test
>>
>> require 'spec_helper'
>>
>> describe Product do
>>
>> it "is valid with a productname, description,price and a
>> image_url" do
>> product = Product.new(
>> title = "Book 1" ,
>> description = "This is the first book" ,
>> price = "1.00")
>> expect(product).to be_valid
>> end
>> end
>>
>> But as soon as I do rspec I see this output:
>>
>>
>> MiniTest::Unit::TestCase is now Minitest::Test. From
>> /home/codio/.rbenv/versions/2.1.5/lib/ruby/2.1.0/test/unit/testcase.rb:8:in
>> `<module:Unit>'
>>
>>
>>
>>
>>
>> Product
>>
>>
>>
>> is valid with a productname, description,price and a image_url (FAILED - 1)
>>
>>
>>
>>
>>
>>
>>
>> Failures:
>>
>>
>>
>>
>>
>>
>>
>> 1) Product is valid with a productname, description,price and a image_url
>>
>>
>> Failure/Error: product = Product.new(
>>
>>
>> ArgumentError
>> :
>>
>> wrong number of arguments (3 for 0..2)
>>
>>
>>
>> # ./spec/model/product_spec.rb:6:in `block (2 levels) in <top
>> (required)>'
>>
>>
>>
>> Where did i took the wrong turn.
>>
>> Roelof
>>
>
> Change this:
>
> Product.new(
> title = "Book 1" ,
> description = "This is the first book" ,
> price = "1.00")
>
> to:
>
> Product.new(
> title: "Book 1" ,
> description: "This is the first book" ,
> price: "1.00")
>
> In the first case, you are passing 3 positional arguments, and assigning
> them to local variables `title`, `description` and `price`. In the second,
> you are passing a single positional argument, which is a hash containing
> `:title`, `:description` and `:price`. ActiveRecord only supports the
> latter.
>
> HTH,
> Myron
>
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/9090f6c5-25a9-48d2-99bf-67624d70f0bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.