ruby - LocalJumpError: no block given -


i keep getting error while running rspec file:

failures:                                                                                                                                      1) book title should capitalize first letter                                                                                               failure/error: @book.title("inferno")                                                                                                       localjumperror:                                                                                                                               no block given (yield)                                                                                                                    # ./08_book_titles.rb:7:in `title'   

here book_title.rb

class :: book    attr_accessor :some_title  def title(some_title) little_words = %w(of , on under or nor yet @ around after along on without)   some_title = yield   some_title.split.each_with_index.map{|x, index| little_words.include?(x) && index > 0 ? x : x.capitalize }.join(" ") end #def  end 

and here rspec file (or @ least first spec):

require_relative '08_book_titles'  describe book    before     @book = book.new   end    describe 'title'     'should capitalize first letter'       @book.title("inferno")       @book.title.should == "inferno"     end end 

i have included yield in method, , there block in spec...so don't understand why not calling block. have tried think of calling directly on map (instead of using variable assigned to) calling separately on own using on map, trying pass in argument of title in method...to see now. have read through ton of threads. not seeing?

i see future exercises running specs on custom classes love tips (or links) on things need know or out while testing custom classes rspec. thanks!

updated

so have changed book_title.rb this:

  class :: book    def title little_words = %w(of , on under or nor yet @ around after along on without)     self.split.each_with_index.map{|x, index| little_words.include?(x) && index > 0 ? x : x.capitalize }.join(" ") end #def  end 

and because i, incorrectly, edited specs- reverted them this:

require '08_book_titles'  describe book    before     @book = book.new   end    describe 'title'     'should capitalize first letter'       @book.title = "inferno"       @book.title.should == "inferno"     end end 

and error this:

failure/error: @book.title = "inferno"                                                                                                      nomethoderror:                                                                                                                                undefined method `title=' #<book:0x007f292a06c6b0>                                                                                    # ./08_book_titles_spec.rb:26:in `block (3 levels) in <top (required)>'  

you're mis-using yield , no, there's no block in spec. if there was, spec like...

  @book.title("inferno")     "inferno"   end 

see block added? don't need block , shouldn't use yield

you seem thinking need yield access argument... don't. title method should use passed argument directly...

def title(new_title) little_words = %w(of , on under or nor yet @ around after along on without)   @some_title = new_title.split.each_with_index.map{|x, index| little_words.include?(x) && index > 0 ? x : x.capitalize }.join(" ") end #def 

finally, test calling title method twice, when should call once , use attr_accessor method test result.

it 'should capitalize first letter'   @book.title("inferno")   @book.some_title.should == "inferno" end 

Popular posts from this blog