Sha256: 443b2323e1d0a9cee46b44dc5591419c5632aec60db6598c03797882bc541032
Contents?: true
Size: 1.42 KB
Versions: 8
Compression:
Stored size: 1.42 KB
Contents
require "test_helper" class CustomerErrorTest < MiniTest::Spec let(:key) { :name } let(:error_text) { "text2" } let(:starting_error) { [OpenStruct.new(errors: {title: ["text1"]})] } let(:custom_error) { Reform::Contract::CustomError.new(key, error_text, @results) } before { @results = starting_error } it "base class structure" do assert_equal custom_error.success?, false assert_equal custom_error.failure?, true assert_equal custom_error.errors, key => [error_text] assert_equal custom_error.messages, key => [error_text] assert_equal custom_error.hint, {} end describe "updates @results accordingly" do it "add new key" do custom_error assert_equal @results.size, 2 errors = @results.map(&:errors) assert_equal errors[0], starting_error.first.errors assert_equal errors[1], custom_error.errors end describe "when key error already exists in @results" do let(:key) { :title } it "merge errors text" do custom_error assert_equal @results.size, 1 assert_equal @results.first.errors.values, [%w[text1 text2]] end describe "add error text is already" do let(:error_text) { "text1" } it 'does not create duplicates' do custom_error assert_equal @results.size, 1 assert_equal @results.first.errors.values, [%w[text1]] end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems