English 中文(简体)
Question about Cucumber/Pickle
原标题:

I m trying to get a little more familiarity with Rails / ActiveRecord. In trying to do so I am attempting to use Cucumber to help with some "discovery" tests.

I have the following

Feature: Describing a task
  In order to work with tasks
  As a user
  I want to be able to know what makes up a task and to improve my understanding of ActiveRecord


Scenario: A task has certain core fields
  Given the following tasks exist
  | id | name      |
  | 1  | some task |
  And the following estimates exist
  | task_id | hours | explanation                           |
  | 1       | 8     | initial estimate                      |
  | 1       | 6     | better undertsanding of task          |
  | 1       | 16    | no control over inputs to create task |
  | 2       | 22    | for other task |

Then a task: "task" should exist with name: "some task" #this works
Then the estimate "estimate" should exist with explanation: "initial estimate" #this works
Then the estimate "estimate" should be one of task: "task" s estimates #this works
Then the task "task" should have 3 estimates  #this one fails

EDIT

I have no custom steps - trying to use use what comes out of the box with cucumber and pickle (just to limit my confusion).

The models are

class Estimate < ActiveRecord::Base

  belongs_to :Task, :class_name => "Task", :foreign_key => "Task_id"

end

and

class Task < ActiveRecord::Base
  has_many :estimates
end

Can anyone point me in the right direction (or if I need to post more code)?

Thanks,

Joe

问题回答

Your estimate class can look like this:

class Estimate ...
  belongs_to :task
end 

It will infer the table name and the fk and assuming you ve been following the rails database idioms it should all just work.

As for your cuke steps, I ve never used pickle, so I m not sure what s going on with that, but if the step that s failing is:

Then the task "task" should have 3 estimates  #this one fails

It might be to related to the change I ve outlined above (maybe it s doing something weird with the table name??).





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签