spec/unit/settings_spec.rb in evil-client-1.1.0 vs spec/unit/settings_spec.rb in evil-client-2.0.0

- old
+ new

@@ -1,25 +1,56 @@ RSpec.describe Evil::Client::Settings do let(:settings) { klass.new(logger, options) } let(:log) { StringIO.new } let(:logger) { Logger.new log } - let(:klass) { Class.new(described_class) } + let(:schema) { double :schema, to_s: "Test::Api.users.update" } + let(:klass) { described_class.for(schema) } let(:options) { { "id" => 42, "name" => "Andrew" } } let(:dsl_methods) do %i[options datetime logger scope basic_auth key_auth token_auth] end - before { klass.instance_variable_set :@schema, "Test::Api.users.update" } + describe ".for" do + subject { klass } - describe ".schema" do - subject { klass.schema } + it "subclasses itself" do + expect(subject.superclass).to eq described_class + end - it "returns the schema class the settings belongs to" do - expect(subject).to eq "Test::Api.users.update" + it "keeps the schema" do + expect(subject.schema).to eq schema end end + describe ".policy" do + context "for the root schema settings" do + subject { klass.policy } + + it "subclasses Evil::Client::Policy" do + expect(subject.superclass).to eq Evil::Client::Policy + end + + it "refers back to the settings" do + expect(subject.settings).to eq klass + end + end + + context "for the scope settings" do + let(:scope_schema) { double :scope_schema } + let(:scope_klass) { klass.for(scope_schema) } + subject { scope_klass.policy } + + it "subclasses policy of parent settings" do + expect(subject.superclass).to eq klass.policy + end + + it "refers back to the settings" do + expect(subject.settings).to eq scope_klass + end + end + end + describe ".option" do it "is defined by Dry::Initializer DSL" do expect(klass).to be_a Dry::Initializer end @@ -69,25 +100,18 @@ end describe ".validate" do before do klass.param :name - klass.validate(:name_present) { name.to_s != "" } + klass.validate { errors.add :name_present if name.to_s == "" } end let(:options) { { "name" => "" } } it "adds validation for an instance" do # see spec/fixtures/locale/en.yml expect { settings } - .to raise_error(Evil::Client::ValidationError, "The user has no name") - end - - it "gives logger to validators" do - settings rescue nil - - expect(log.string).to include "#{klass.schema}.validator[:name_present]" - expect(log.string).to include "failed" + .to raise_error(Evil::Client::ValidationError, /The user has no name/) end end describe ".name" do subject { klass.name }