Sha256: 739996268d03b34f9c18a2cae57b3110faf863525331d2b9964e306e41360365
Contents?: true
Size: 1 KB
Versions: 2
Compression:
Stored size: 1 KB
Contents
require 'test_helper' class SkipTest < MiniTest::Spec representer! do property :title property :band, skip_parse: lambda { |fragment, opts| opts[:skip?] and fragment["name"].nil? }, class: OpenStruct do property :name end collection :airplays, skip_parse: lambda { |fragment, opts| puts fragment.inspect; opts[:skip?] and fragment["station"].nil? }, class: OpenStruct do property :station end end let (:song) { OpenStruct.new.extend(representer) } # do parse. it { song.from_hash({"band" => {"name" => "Mute 98"}}, skip?: true).band.name.must_equal "Mute 98" } it { song.from_hash({"airplays" => [{"station" => "JJJ"}]}, skip?: true).airplays[0].station.must_equal "JJJ" } # skip parsing. it { song.from_hash({"band" => {}}, skip?: true).band.must_equal nil } # skip_parse is _per item_. let (:airplay) { OpenStruct.new(station: "JJJ") } it { song.from_hash({"airplays" => [{"station" => "JJJ"}, {}]}, skip?: true).airplays.must_equal [airplay] } end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
representable-2.1.1 | test/skip_test.rb |
representable-2.1.0 | test/skip_test.rb |