spec/morpheus/mixins/introspection_spec.rb in morpheus-0.3.6 vs spec/morpheus/mixins/introspection_spec.rb in morpheus-0.3.7

- old
+ new

@@ -1,154 +1,111 @@ require 'spec_helper' -describe Morpheus::Introspection, ".valid?" do - - before(:each) do - @dog = Dog.new - end - - context "when the errors hash is empty" do - - it "returns true" do - @dog.name = "Fido" - @dog.should be_valid +describe Morpheus::Introspection do + + describe '#persisted?' do + before(:each) do + @attendee = Attendee.new end - - end - - context "when the errors hash is not empty" do - - it "returns false" do - @dog.should_not be_valid + + context 'when the record is not persisted' do + it 'returns false' do + @attendee.should_not be_persisted + end end - - end - -end -describe Morpheus::Introspection, ".persisted?" do + context 'when the record is persisted' do + before(:each) do + stub_web! + @attendee.save + end - before(:each) do - @attendee = Attendee.new - end - - context "when the record is not persisted" do - - it "returns false" do - @attendee.should_not be_persisted + it 'returns true' do + @attendee.should be_persisted + end end - - end - - context "when the record is persisted" do - - before(:each) do - stub_web! - @attendee.save + + def stub_web! + Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/attendees").and_return(build_morpheus_response( + 201, + { + :id => 1, + :valid => true, + :errors => {} + } + )) end - - it "returns true" do - @attendee.should be_persisted - end - - end - - def stub_web! - Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/attendees").and_return(build_morpheus_response( - 201, - { - :id => 1, - :valid => true, - :errors => {} - } - )) - end -end - -describe Morpheus::Introspection, ".new_record?" do - - before(:each) do - @attendee = Attendee.new end - - context "when the record is new" do - - it "returns true" do - @attendee.should be_new_record - end - - end - - context "when the record is not new" do - + + describe '#new_record?' do before(:each) do - stub_web! - @attendee.save + @attendee = Attendee.new end - - it "returns false" do - @attendee.should_not be_new_record + + context 'when the record is new' do + it 'returns true' do + @attendee.should be_new_record + end end - - end - - def stub_web! - Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/attendees").and_return(build_morpheus_response( - 201, - { - :id => 1, - :valid => true, - :errors => {} - } - )) - end - -end -describe Morpheus::Introspection, ".destroyed?" do + context 'when the record is not new' do + before(:each) do + stub_web! + @attendee.save + end - it "returns false" do - Dog.new.should_not be_destroyed - end + it 'returns false' do + @attendee.should_not be_new_record + end + end -end + def stub_web! + Morpheus::Configuration.hydra.stub(:post, "#{Morpheus::Configuration.host}/attendees").and_return(build_morpheus_response( + 201, + { + :id => 1, + :valid => true, + :errors => {} + } + )) + end -describe Morpheus::Introspection, ".respond_to?" do - - before(:each) do - @dog = Dog.new(:name => "Fido", :age => 10) end - - context "if the query method is a method on the object" do - it "returns true" do - @dog.should respond_to(:bark!) + describe '#destroyed?' do + it 'returns false' do + Dog.new.should_not be_destroyed end - end - - context "if the query method is not a method on the object" do - it "returns false" do - @dog.should_not respond_to(:bite!) + describe '#respond_to?' do + before(:each) do + @dog = Dog.new(:name => 'Fido', :age => 10) end - - end - - context "if the query method is an attribute on the object" do - it "returns true" do - @dog.should respond_to(:age) + context 'if the query method is a method on the object' do + it 'returns true' do + @dog.should respond_to(:bark!) + end end - - end - - context "if the query method is not an attribute on the object" do - it "returns false" do - @dog.should_not respond_to(:weight) + context 'if the query method is not a method on the object' do + it 'returns false' do + @dog.should_not respond_to(:bite!) + end end - + + context 'if the query method is an attribute on the object' do + it 'returns true' do + @dog.should respond_to(:age) + end + end + + context 'if the query method is not an attribute on the object' do + it 'returns false' do + @dog.should_not respond_to(:weight) + end + end end end