Ruby on Rails rspec test with language -
i have ruby on rails application , try test using rspec.firstly, don't have errors while i'm testing in turkish mode. however, when test in english mode, i'm getting error.
the followings modals.
company.rb
class company < applicationrecord has_many :employees end
employee.rb
class employee < applicationrecord belongs_to :company end
these factory files.
companies.rb
factorygirl.define factory :company end end
employees.rb
factorygirl.define factory :employee factory :employee_with_company before(:create) |employee| employee.company = create(:company) end end end end
my employee_spec.rb
require 'rails_helper' require 'shoulda/matchers' rspec.describe employee, type: :model before(:each) { @employee = factorygirl.create(:employee_with_company) } subject { @employee } { should belong_to :company } { should validate_presence_of :company } end
when add following line application.rb file , run test command "bundle exec rspec -b", that's ok, no problem.
bundle exec rspec -b config.i18n.default_locale = :tr
on other hand, when try test application in english mode addint following line application.rb, i'm getting error on validates_presence_of :company.
config.i18n.default_locale = :en
and error,
employee should validate :company cannot empty/falsy failure/error: { should validate_presence_of :company } employee did not validate :company cannot empty/falsy. after setting :company ‹nil›, matcher expected employee invalid , produce validation error "can't blank" on :company. record indeed invalid, produced these validation errors instead: * company: ["must exist"]
there no difference in code. difference :tr , :en. can't figure out why i'm getting error.
any suggestions ?
thanks.
Comments
Post a Comment