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

Posted by 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
Posted by 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
Posted by 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!
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.