Getting Desired behaviour when I run the program, but spec still fails

I’m not doing something right with the following spec and code:

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

On 08/31/2011 07:09 AM, Ash M. 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 :wink: (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!

On 31 Aug 2011, at 09:22, GB Hoyt wrote:

I’m not doing something right with the following spec and code:
test and code, code works, test fails. · GitHub

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 :wink: (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