Sha256: 2775ae6c72d48fb0860bd9d01d7e30c25b667ac78b89968597b8b44831ca21e8
Contents?: true
Size: 1.19 KB
Versions: 4
Compression:
Stored size: 1.19 KB
Contents
require 'spec_helper' describe DiscourseApi::API::Params do def params_for(h) DiscourseApi::API::Params.new(h).required(:r1).optional(:o1, :o2).default(d1: "default") end it "should raise on missing required params" do expect { params_for({o1: "test"}).to_h }.to raise_error(ArgumentError) end it "should not raise when a required param is false" do expect { params_for({r1: false}).to_h }.not_to raise_error end it "should not include optional params when not provided" do expect(params_for({r1: "test"}).to_h).not_to include(:o1) end it "should include optional params if provided but blank" do expect(params_for({r1: "test", o2: nil}).to_h).to include(:o2) end it "should include default params when defined but not provided" do expect(params_for({r1: "test"}).to_h).to include(d1: "default") end it "should include default params when defined and provided" do expect(params_for({r1: "test", d1: "override"}).to_h).to include(d1: "override") end it "should include optional and default params when defined and provided" do expect(params_for({r1: "test", o1: "optional", d1: "override"}).to_h).to include(o1: "optional", d1: "override") end end
Version data entries
4 entries across 4 versions & 1 rubygems