ruby on rails - testing with rspec codeschool level 5 challenge 4 -


here base question test:

we've changed code below we're mocking zombiemailer.tweet method instead of entire method. there still more make example work. first, finish let(:mail) statement below creating stub deliver method returns true. update mock call tweet method returns mail stub created.  

unfortunately can not alter models, question, or mailer.

models:

# tweet.rb class tweet < activerecord::base   belongs_to :zombie   validates :message, presence: true   attr_accessible :message    after_create :email_tweeter    def email_tweeter     zombiemailer.tweet(zombie, self).deliver   end   private :email_tweeter end  # zombie.rb class zombie < activerecord::base   has_many :tweets   validates :email, presence: true   attr_accessible :email end 

mailer:

class zombiemailer < actionmailer::base   def tweet(zombie, tweet)     mail(:from => 'admin@codeschool.com',          :to => zombie.email,          :subject => tweet.message)   end end 

i keep bouncing around on , use few pointers. here have been working got past test question 3. asking add deliver method, method not exist, or @ least not placing in correct place.

updated

describe tweet   context 'after create'     let(:zombie) { zombie.create(email: 'anything@example.org') }     let(:tweet) { zombie.tweets.new(message: 'arrrrgggghhhh') }     let(:mail) { stub(:deliver => true) }      'calls "tweet" on zombiemailer'       zombiemailer.should_receive(:tweet).returns(:mail)       tweet.save     end   end end 

and error message is:

failures:  1) tweet after create calls "tweet" on zombiemailer failure/error: zombiemailer.should_receive(:tweet).returns(:mail) nomethoderror: undefined method `returns' #<rspec::mocks::messageexpectation:0x0000000519ab90> # zombie_spec.rb:8:in `block (3 levels) '  finished in 0.37725 seconds 1 example, 1 failure  failed examples:  rspec zombie_spec.rb:7 # tweet after create calls "tweet" on zombiemailer 

any rspec peeps out there can point me in right direction missing here? thank you.

thank @paritosh , @alex comments above, here final answer.

describe tweet   context 'after create'     let(:zombie) { zombie.create(email: 'anything@example.org') }     let(:tweet) { zombie.tweets.new(message: 'arrrrgggghhhh') }      let(:mail) { stub(:deliver => true) }      'calls "tweet" on zombiemailer'       zombiemailer.should_receive(:tweet).and_return(mail)       tweet.save     end   end end 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -