0

The following code doesn't compile in ruby 2.1 on OS X. The error message is quite strange:

/Library/Ruby/Gems/2.0.0/gems/rake-10.3.2/lib/rake/rake_test_loader.rb:10:in `require':
  /Users/jayunit100/Development/leitmotif/test/test_leitmotif.rb:21: 
    syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError)

That is, it is requesting that i remove the final "end" statement from the class, and when i do so, it indeed compiles ! So my first question is , how or why it is that the rake_test_loader wants a class declaration without a closing end block.

require 'helper'
require 'minitest/autorun'

class TestLeitmotif < MiniTest::Test
    ### A simple test
    context "Leitmotif core tests" do
            setup do
                @lm = Leitmotif.new
            end

            should "run should return 1 if arguments are invalid"
                @lm=Leitmotif.new 
                print("\nASDF\n")
                print(@lz.inspect);
                print(@lm.inspect)
                print("\nASDF\n")
                x=@lm.run("","")
                #assert_equal 1, x
            end
    end
end

My second problem here is that the variable

@lm = Leimotif.new

Which is declared in the setup block, seems to be inaccessible in the should method.

My suspicion here is that somehow the syntax of the should framework is not parsed correctly in the current version of ruby, but am quite new to ruby so any insight would be appreciated.

Thanks!

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
jayunit100
  • 17,388
  • 22
  • 92
  • 167
  • This is either a typo or a misunderstanding of Ruby's block syntax. The reason removing the `end` works is because you're then doing all the stuff you meant to be in the `should` block at the class level. – Dave Newton Nov 10 '14 at 14:46

1 Answers1

0

This error is because you are missing the do at the beginning of the block passed to should.

should "run should return 1 if arguments are invalid" do
  @lm=Leitmotif.new 
  print("\nASDF\n")
  print(@lz.inspect);
  print(@lm.inspect)
  print("\nASDF\n")
  x=@lm.run("","")
  #assert_equal 1, x
end

Most implementations of shoulda on Minitest simply alias the Minitest Spec DSL's it to should, so those docs should help.

blowmage
  • 8,854
  • 2
  • 35
  • 40