Sha256: 7262ee506b234087e98489689db4a355508d2472d3803c076374052a56779930
Contents?: true
Size: 1.92 KB
Versions: 1
Compression:
Stored size: 1.92 KB
Contents
RSpec.describe "RSpec matchers:" do subject { Test::UserPolicy[name: nil] } before do I18n.available_locales = %i[en] I18n.backend.store_translations \ :en, { "test/user_policy" => { "name_presence" => "Name is absent" } } class Test::UserPolicy < Tram::Policy option :name validate :name_presence private def name_presence return if name errors.add :name_presence, field: "name" end end end describe "to be_invalid_at" do it "passes when some translated error present w/o tags constraint" do expect do expect { subject }.to be_invalid_at end.not_to raise_error end it "passes when some translated error present under given tags" do expect do expect { subject }.to be_invalid_at field: "name" end.not_to raise_error end it "fails when no errors present under given tags" do expect do expect { subject }.to be_invalid_at field: "email" end.to raise_error RSpec::Expectations::ExpectationNotMetError end it "fails when some translations are absent" do I18n.available_locales = %i[ru en] expect do expect { subject }.to be_invalid_at field: "name" end.to raise_error RSpec::Expectations::ExpectationNotMetError end end describe "not_to be_invalid_at" do it "passes when no errors present under given tags" do expect do expect { subject }.not_to be_invalid_at field: "email" end.not_to raise_error end it "fails when some error present under given tags" do expect do expect { subject }.not_to be_invalid_at field: "name" end.to raise_error RSpec::Expectations::ExpectationNotMetError end it "fails when some error present w/o tags constraint" do expect do expect { subject }.not_to be_invalid_at end.to raise_error RSpec::Expectations::ExpectationNotMetError end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tram-policy-0.0.1 | spec/tram/policy/matchers_spec.rb |