Forum: RSpec Getting Desired behaviour when I run the program, but spec still fails.

8e5adba4e895d68a835efbcfb03958f0?d=identicon&s=25 GB Hoyt (Guest)
on 2011-08-31 10:30
(Received via mailing list)
I'm not doing something right with the following spec and code:
https://gist.github.com/1183066

My problem lies in the last Spec:

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 My currently pain rattled body and mind is not processing the
problem very well. I suspect I'm not writing the spec right, any help?
Thanks, GB Hoyt Lakeland, FL
E540cdc2ce3a8fc669d040143ed3d461?d=identicon&s=25 Ash Moran (Guest)
on 2011-08-31 13:41
(Received via mailing list)
On 31 Aug 2011, at 09:22, GB Hoyt wrote:

> I'm not doing something right with the following spec and code:
> https://gist.github.com/1183066
>
> My problem lies in the last Spec:
>
> 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 My currently pain rattled body and mind is not processing the
> problem very well. I suspect I'm not writing the spec right, any help?

>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

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


--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashmoran
8e5adba4e895d68a835efbcfb03958f0?d=identicon&s=25 GB Hoyt (Guest)
on 2011-08-31 16:07
(Received via mailing list)
On 08/31/2011 07:09 AM, Ash Moran wrote:
>     @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!
This topic is locked and can not be replied to.