views:

35

answers:

1

I have this spec:

it 'can parse armies with only section headers' do
  list = <<-LIST
  :Core
  :Special
  :Omgg
  :Moarheaders
  LIST
  expected_output = "## Core\n## Special\n## Omgg\n## Moarheaders\n"
  parsed = @parser.parse(list)
  parsed.should_not be_nil
  parsed.transform.should be expected_output
end

Which produces this output:

expected ## Core
## Special
## Omgg
## Moarheaders
, got "## Core\n## Special\n## Omgg\n## Moarheaders\n"

If I remove the double quotes, I get this output:

expected ## Core\n## Special\n## Omgg\n## Moarheaders\n, 
got     "## Core\n## Special\n## Omgg\n## Moarheaders\n"

If I add quotes to my expected_output, I get this: (expected_output = '"## Core\n## Special\n## Omgg\n## Moarheaders\n"')

expected "## Core\n## Special\n## Omgg\n## Moarheaders\n", 
got      "## Core\n## Special\n## Omgg\n## Moarheaders\n"

What's going on here?

I can't get the Treetop result to evaluate the \n as newlines, and I can't get the expected_output to match regardless of what I try.

I'm confused.

+1  A: 

Did you try:

parsed.transform.should == expected_output

be might use object identity instead of comparing the string values.

zetetic
Ahh, can't believe I overlooked that. Thanks so much. That was the trick. :)
Josiah Kiehl
Well I didn't know that `be` acted that way, so I learned something too.PS. Would you mind accepting the answer?
zetetic