>From what I see, you're trying to create  Give instance with the contents
of valid_attributes variabble, but you have not defined what that variable
references. That I think, is the reason of the error you are getting.
On Nov 8, 2012 6:55 AM, "Soichi Ishida" <[email protected]> wrote:

> Rails 3.1.3
> RSpec latest
>
> I have started using rspec a few days ago, although I had used Rails for a
> while.
>
> I have started developing a Rails application without thinking about tests
> at all, and in the middle of the development, realized the importance of
> BDD (or TDD). (Please don't say "You should have done it from the
> beginning")
> so many features including models and controllers are already in action.
> They work fine up to this point.
>
> Now I have installed rspec and rspec-rails, and generated necessary files
> such as xxx_controllers_spec.rb.
>
> Then run the test,
>
>    bundle exec rspec spec/controllers/gives_controller_spec.rb
>
>
> The result is a large list of errors, and  I have questions about "index"
> part this time.
>
> gives_controller_spec.rb has the following index part by default
>
>   describe "GET index" do
>>     it "assigns all gives as @gives" do
>>       give = Give.create! valid_attributes
>>       get :index, {}, valid_session
>>       assigns(:gives).should eq([give])
>>     end
>>   end
>
>
> and the corresponding error is
>
>   1) GivesController GET index assigns all gives as @gives
>>      Failure/Error: give = Give.create! valid_attributes
>>      ActiveRecord::RecordInvalid:
>>        Validation failed: Flight name can't be blank, Day departure can't
>> be blank, Check in can't be blank, Weight can't be blank, User can't be
>> blank
>>      # ./spec/controllers/gives_controller_spec.rb:39:in `block (3
>> levels) in <top (required)>'
>
>
> and gives.rb is
>
> class Give < ActiveRecord::Base
>>   after_initialize :set_initial_date
>>   belongs_to :user
>>   validates :flight_name_id, :presence => true
>>   validates :day_departure, :presence => true
>>   validates :check_in, :presence => true
>>   validates :weight, :presence => true
>>   validates :user_id, :presence => true
>>   belongs_to :flight_name
>>   def set_initial_date
>>     @day_departure ||= Date.today
>>   end
>> end
>
>
>
> Questions:
>
> 1. Doesn't rspec generate default controllers so that the initial test
> will succeed?
> 2. Can you guess the cause of the error?
>
> I also created fixtures/gives.yml
>
> one:
>  check_in: true
>  weight:      4
>  user_id:     2
>  day_departure: "2012-12-01"
>  flight_name_id: 3
>
> and ran
>
> rake db:fixtures:load
>
>
> 3. I don't quite understand the role of fixtures. Doesn't rspec
> automatically pick up the data from here?
>
> I appreciate if you help me out.
>
>
> soichi
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "rspec" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rspec/-/6XTfyJUnayEJ.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to