require 'spec_helper' describe Zelda::Zender do describe "when retrieving a list of zenders" do it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("zenders") Zelda::Zender.all end end describe "when retrieving a specific zender" do before(:each) do zender_attrs = { "zender" => {"code" => "NL1", "name" => "Nederland 1"} } Zelda::Request.stub!(:get).with("zenders/1").and_return zender_attrs end def find_zender Zelda::Zender.find(1) end it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("zenders/1") find_zender end it "should return a new Zender" do find_zender.should be_a(Zelda::Zender) end it "should return nil if the zender cannot be found" do Zelda::Request.stub!(:get).and_return nil find_zender.should be_nil end it "should return the correct name" do find_zender.name.should == "Nederland 1" end end describe "series" do before(:each) do @zender = Zelda::Zender.new('id' => '1') Zelda::Request.stub!(:get).and_return('zender' => {'series' => {'serie' => [{'foo' => 'bar'}]}}) end def find_series @zender.series end it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("zenders/1/series") find_series end it "should return an array of series" do find_series.first.should be_a(Zelda::Serie) end end describe "current series" do before(:each) do @zender = Zelda::Zender.new('id' => '1') Zelda::Request.stub!(:get).and_return('zender' => {'series' => {'serie' => [{'foo' => 'bar'}]}}) end def find_series @zender.current_series end it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("zenders/1/current_series") find_series end it "should return an array of series" do find_series.first.should be_a(Zelda::Serie) end end end