Ruby on Rails
Tuesday, February 11, 2014
Hello all,
I am trying to understand when I try to run a test in cucumber what I am missing that it is failing. I am using FactoryGirl to create my records and using cucumber to test my logic however I know that I am doing something wrong in my testing I just can't seem to figure out what. Here is what I have:
Feature:
Feature: All features related to staff info
Scenario: notification for empty shirt size
Given there is at least 1 staff info record
When the shirt size field is empty
And the shirt size check is run
Then the system should send an email notification
Steps:
Given(/^there is at least (\d+) staff info record$/) do |arg1|
assert_difference('StaffInfo.count', 1) do
@staff_info = FactoryGirl.create :staff_info
end
end
When(/^the shirt size field is empty$/) do
assert @staff_info.update_attribute(:shirt_size, nil)
end
When(/^the shirt size check is run$/) do
StaffInfo.check_empty_shirt_fields
end
Then(/^the system should send an email notification$/) do
pending # express the regexp above with the code you wish you had
end
Model:
class StaffInfo < ActiveRecord::Base
belongs_to :person
scope :empty_shirt_fields, -> { where('shirt_size in (?)', [nil, '']) }
def self.check_empty_shirt_fields
staff_with_missing_shirt_sizes = StaffInfo.empty_shirt_fields
debugger
send_empty_shirt_size_notification staff_with_missing_shirt_sizes if staff_with_missing_shirt_sizes.size > 0
end
def send_empty_shirt_size_notification(staff_records)
Mailer.missing_shirt_size(staff_records).deliver
end
end
What is happening is, when I hit the 3rd test I did a check to see if the record was present (StaffInfo.count) and it was. But after running StaffInfo.check_empty_shirt_fields, I did a check for the record and it was gone. I am not understanding how my record could have disappeared when I all my method was doing was checking for any records with a missing field.
Anyone have any ideas?
-- I am trying to understand when I try to run a test in cucumber what I am missing that it is failing. I am using FactoryGirl to create my records and using cucumber to test my logic however I know that I am doing something wrong in my testing I just can't seem to figure out what. Here is what I have:
Feature:
Feature: All features related to staff info
Scenario: notification for empty shirt size
Given there is at least 1 staff info record
When the shirt size field is empty
And the shirt size check is run
Then the system should send an email notification
Steps:
Given(/^there is at least (\d+) staff info record$/) do |arg1|
assert_difference('StaffInfo.count', 1) do
@staff_info = FactoryGirl.create :staff_info
end
end
When(/^the shirt size field is empty$/) do
assert @staff_info.update_attribute(:shirt_size, nil)
end
When(/^the shirt size check is run$/) do
StaffInfo.check_empty_shirt_fields
end
Then(/^the system should send an email notification$/) do
pending # express the regexp above with the code you wish you had
end
Model:
class StaffInfo < ActiveRecord::Base
belongs_to :person
scope :empty_shirt_fields, -> { where('shirt_size in (?)', [nil, '']) }
def self.check_empty_shirt_fields
staff_with_missing_shirt_sizes = StaffInfo.empty_shirt_fields
debugger
send_empty_shirt_size_notification staff_with_missing_shirt_sizes if staff_with_missing_shirt_sizes.size > 0
end
def send_empty_shirt_size_notification(staff_records)
Mailer.missing_shirt_size(staff_records).deliver
end
end
What is happening is, when I hit the 3rd test I did a check to see if the record was present (StaffInfo.count) and it was. But after running StaffInfo.check_empty_shirt_fields, I did a check for the record and it was gone. I am not understanding how my record could have disappeared when I all my method was doing was checking for any records with a missing field.
Anyone have any ideas?
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f889916a-e2c5-4add-ab18-89922dc73d73%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment