[rspec-users] Getting Desired behaviour when I run the program, but spec still fails.

GB Hoyt qrprat77 at gmail.com
Wed Aug 31 08:57:55 EDT 2011


On 08/31/2011 07:09 AM, Ash Moran wrote:
>
> >From just a quick skim over, these two examples look contradictory:
>
>   it "should throw an error if asked to display a menu that does not exist" 
>     @menu.display_menu(@messenger).should == "#{@menu.txtfile} does not exist!"
>   end
>
>   #Here's my problem child
>   it "should load the contents of the text file into the action list" do
>     @menu.action_list.empty?.should == false
>     @menu.display_menu(@messenger)
>   end
>

yeah, I realized that shortly after posting it, and I modified the spec
as such:

#Here's the spec:
module Antlers
  describe Menu do
    context "display a Menu from a text file" do
      before (:each) do
        @messenger = mock("messenger").as_null_object
        @menu = Menu.new("Main Menu")
      end #before
...
       #This spec passes

      it "should throw an error if asked to display a menu that does not
exist" do
        menu2 = Menu.new("Title_Menu")
        menu2.display_menu(@messenger).should == "#{menu2.txtfile}does
not exist!"
      end
#this spec does not pass, the object is initialized with an empty hash,
the display_menu method #populates that hash. That's how it behaves in
usage
      it "should load the contents of the text file into the action list" do
        @menu.action_list.empty?.should == false
        @menu.display_menu(@messenger)
      end
    end #new menu context
  end #menu
end #module


I wonder if it has something to do with @messenger being a mock null object?
> Do you need two separate contexts, one with `Menu.new("Title_test_real.txt")`?
>
> BTW… s/\t/  /g ;) (Conventional Ruby indents are 2 spaces, tabs make it harder to read for people used to that)
>
> HTH, if not, maybe someone else can see the bug.
>
> Ash
>
>
bah, I always forget to check how geany marks tabs.  I fixt it!




More information about the rspec-users mailing list