Old syntax? what's going on here

I have this in a _spec.rb file: (a gem I inherited at work)

Open3.expects(:popen3).with do |command|
case part_of_command
when Regexp: command =~ part_of_command
when String: command.include?(part_of_command)
else raise “Can’t match that”
end
end

which ruby is complaining about:

spec/ruby_gpg_spec.rb:7: syntax error, unexpected ‘:’, expecting
keyword_then or ‘,’ or ‘;’ or ‘\n’
when Regexp: command =~ part_of_command
^
spec/ruby_gpg_spec.rb:8: syntax error, unexpected keyword_when,
expecting keyword_end
when String: command.include?(part_of_command)
^
spec/ruby_gpg_spec.rb:9: syntax error, unexpected keyword_else,
expecting keyword_end
else raise “Can’t match that”
^
spec/ruby_gpg_spec.rb:241: syntax error, unexpected keyword_end,
expecting $end

I’m completely unfamiliar with what is supposed to be happening above,
but I rather assume that Regexp: and String: have something to do with
the Open3.expects bit.

I’m a bit pressed for time right now, can anyone give me some fast
pointers? Already delving into Open3…

Subject: old syntax? what’s going on here
Date: mar 05 feb 13 10:33:35 +0900

Quoting tamouse mailing lists ([email protected]):

I have this in a _spec.rb file: (a gem I inherited at work)

Open3.expects(:popen3).with do |command|
case part_of_command
when Regexp: command =~ part_of_command
when String: command.include?(part_of_command)
else raise “Can’t match that”
end
end

Are you sure that code ever worked?

From my very worn copy of “Ruby in a nutshell”:

“A when statement’s expression is separated from code by the
reserved word then, a newline, or a semicolon.”

That colon should be a semicolon (or then or a newline)…

Carlo

On Tue, Feb 5, 2013 at 7:47 AM, Carlo E. Prelz [email protected] wrote:

  when String: command.include?(part_of_command)

That colon should be a semicolon (or then or a newline)…

Heh, no – I’ve inherited this little bit of thing that no one in the
group has ever done much with.

On Tue, Feb 5, 2013 at 7:52 AM, tamouse mailing lists
[email protected] wrote:

  when Regexp: command =~ part_of_command

reserved word then, a newline, or a semicolon."

That colon should be a semicolon (or then or a newline)…

Heh, no – I’ve inherited this little bit of thing that no one in the
group has ever done much with.

Sure enough, Carlos. Now it syntax checks. But on to other problems,
namely with the Open3.expects and a later Open3.stub. I’m guessing I
need some kind of mocker; the .gemspec refers to mocha, which I’m
trying to look into.

Am 05.02.2013 14:33, schrieb tamouse mailing lists:

which ruby is complaining about:
expecting keyword_end
else raise “Can’t match that”
^
spec/ruby_gpg_spec.rb:241: syntax error, unexpected keyword_end, expecting $end

I’m completely unfamiliar with what is supposed to be happening above,
but I rather assume that Regexp: and String: have something to do with
the Open3.expects bit.

No. This case statement (with corrected syntax of course)
uses the class of the object referenced by the command
variable to branch execution.

command = ‘list’
case command
when String
puts ‘a String’
when Regexp
puts ‘a Regexp’
else
puts ‘neither String nor Regexp’
end

=> a String

----- Original Message ----
From: “[email protected][email protected]

No. This case statement (with corrected syntax of course)
uses the class of the object referenced by the command
variable to branch execution.

I’m just a tad loss (not on the explanation), but where this is coming
from…

Open3.expects(:popen3).with do |command|
case part_of_command

Here case is looking at a local variable called part_of_command, but we
didn’t
pass that value (did we???), or is that somehow part of command in this
snippet
of code?

Wayne

Subject: Re: old syntax? what’s going on here
Date: mar 05 feb 13 10:54:39 +0900

Quoting tamouse mailing lists ([email protected]):

Sure enough, Carlos. Now it syntax checks. But on to other problems,
namely with the Open3.expects and a later Open3.stub. I’m guessing I
need some kind of mocker; the .gemspec refers to mocha, which I’m
trying to look into.

(it is Carlo, not Carlos - I am Italian… Nothing against the
Spaniards and the Portuguese, of course)

I never used Open3 (never needed). But if I type

ri expects

nothing appears. There must be yet another syntax error, in the sense
that you should have expect, not expects. Indeed, if I type

ri expect

I obtain (among others):

–8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<–
=== Implementation from Mock

expect(name, retval, args=[], &blk)


Expect that method name is called, optionally with args or a blk, and
returns
retval.

@mock.expect(:meaning_of_life, 42)
@mock.meaning_of_life # => 42

@mock.expect(:do_something_with, true, [some_obj, true])
@mock.do_something_with(some_obj, true) # => true

@mock.expect(:do_something_else, true) do |a1, a2|
a1 == “buggs” && a2 == :bunny
end

args is compared to the expected args using case equality (ie, the
‘===’
operator), allowing for less specific expectations.

@mock.expect(:uses_any_string, true, [String])
@mock.uses_any_string(“foo”) # => true
@mock.verify # => true

@mock.expect(:uses_one_string, true, [“foo”]
@mock.uses_one_string(“bar”) # => true
@mock.verify # => raises MockExpectationError
–8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<–

Then, if I ask ri for Mock, nothing comes out, I never used Mock
myself - I know nothing about that. Hmm… looks like this doc is a
leftover from an old installation (mock seems to have been part of
Ruby in the past but it is not there anymore). I expect you will find
stuff about Mock on the net.

Carlo

Am 05.02.2013 15:08, schrieb Carlo E. Prelz:

(it is Carlo, not Carlos - I am Italian… Nothing against the
Spaniards and the Portuguese, of course)

I never used Open3 (never needed). But if I type

ri expects

nothing appears. There must be yet another syntax error, in the sense
that you should have expect, not expects. Indeed, if I type

No! As long as you do not have the same gems on your machine as
have been used for tamouse’s project, that tells you nothing.

The Mocha::Mock class from the mentioned mocha gem class
has an expects method.

@mock.expect(:do_something_else, true) do |a1, a2|

Carlo

No!

The Mock class you are talking about is part of MiniTest,
and rather new.

On Tue, Feb 5, 2013 at 8:27 AM, [email protected] wrote:

trying to look into.
that you should have expect, not expects. Indeed, if I type

@mock.expect(:do_something_else, true) do |a1, a2|

https://github.com/stomar/

This is the ruby_pgp module, which seems quite old(?) but has been
sucked into our code base somehow. I’m at a loss to understand how
this could actually be even passing tests, until I realized there are
no tests for it either! (The gem has tests, lots of them, but they
aren’t run in our own spec tests.) It only cropped up now as we’re
finally using the functionality that it offers at this stage of the
game. It’s a wrapper for the gpg command.

I’m ripping it out of our code base and restoring it to proper Gem
status so we can use it better. I’ve looked at other gpg gems, but
they would involve more work to just get the basic thing we need done,
which is just encrypt and decrypt a single file in a standalone job
that runs once a week.

The mocha gem is mentioned in the gemspec (there’s no Gemfile) but I
can’t figure out where it gets included in this (yet!).

On Tue, Feb 5, 2013 at 8:08 AM, Carlo E. Prelz [email protected] wrote:

(it is Carlo, not Carlos - I am Italian… Nothing against the
Spaniards and the Portuguese, of course)

Deepest apologies. I didn’t even notice that I added the -s until you
pointed it out. So annoying!

I have a name (Tamara) which should be easy to spell. But I seem to
have some weird kind of accent or something so people always are
spelling it wrong: Timera, Camera, TOmara, Tamera, Tamra, …

This only seems to happen with Americans. Others never seem to have a
problem hearing it and knowing how it’s spelled. What’s weird is I’m
American, people say I have virtually no accent of any kind (which
means, I guess, neutral “newscaster” American accent?)

At any rate, I do apologize.

2013/2/5 tamouse mailing lists [email protected]

spec/ruby_gpg_spec.rb:9: syntax error, unexpected keyword_else,
I’m a bit pressed for time right now, can anyone give me some fast
pointers? Already delving into Open3…

The above case syntax is legitimate in ruby 1.8 but not in 1.9.
Refer to
http://blog.grayproductions.net/articles/getting_code_ready_for_ruby_19

Regards,

Park H.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs