Re: [rspec-users] Noob syntax questions regarding rspec book...

2009-07-09 Thread Rick DeNatale
On Thu, Jul 9, 2009 at 12:43 AM,
internetchrisch...@silhouettesolutions.net wrote:
 Hey everyone,

 I appreciate the replies. After I posted I realized I was looking at
 ruby code. It seems this is where my learning curve is going to take a
 leap. I understand Rails, I am starting to understand Rspec and
 Cucumber, and I understand programming. This is my second language,
 but it's the first time I have had to learn something new. I come from
 a foxpro background and it seems I need to dig into the Ruby language
 a little more. I keep forgetting that Rails is simply a framework and
 not the language - the same is true for Rspec. I hope to laugh at my
 mistakes in a year or two :-)

And I tend to think of regular expressions as a language within a
language.  Lot's of programming languages incorporate regular
expressions with slight variations.

-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Noob syntax questions regarding rspec book...

2009-07-08 Thread internetchris
Hey everyone,

I appreciate the replies. After I posted I realized I was looking at
ruby code. It seems this is where my learning curve is going to take a
leap. I understand Rails, I am starting to understand Rspec and
Cucumber, and I understand programming. This is my second language,
but it's the first time I have had to learn something new. I come from
a foxpro background and it seems I need to dig into the Ruby language
a little more. I keep forgetting that Rails is simply a framework and
not the language - the same is true for Rspec. I hope to laugh at my
mistakes in a year or two :-)

Thanks!

Chris Sund

On Jul 7, 9:49 am, ssmithstone stephen.smithst...@gmail.com wrote:
 I to am in the same situation and the meaning of the /^ $/ is a
 regular expression so it matches yours features so in your features is
 you do

 Give some random text I guess some more random test

 the code would run against that given method, hope that makes sense
 and that's my view of the code

 On Jul 7, 4:35 pm, Chris Sund ch...@silhouettesolutions.net wrote:

  Hey Everyone,

  I've been working my way through the Rspec book trying to absorb and
  understand everything. This is my first time with BDD and I'm just
  trying to figure out some simple syntax stuff. My questions revolve
  around some of the syntaxing used in the book. These are really simple
  questions.

  1.) Given /^the secret code is (. . . .)$/ do |code|
          Is (. . . .) simply a place holder? could I use something like
  (- - - -) instead, or does it actually mean something?

  2.) Then /^the mark should be (.*)$/ do |mark|
          Similar questionwhat does .* represent?

  3.) In the following example why don't I pass   |guess| to the When
  statement? I'm sure it has something to do with the (code.split)
  syntax, I'm just not sure what.

  When /^I guess (. . . .)$/ do |code|
  @game.guess(code.split)
  end

  4.) And finally what does (\n) do?

  Then /^the mark should be (.*)$/ do |mark|
    @messenger.string.split(\n).should include(mark)
  end

  Thank You!

  Chris
  ___
  rspec-users mailing list
  rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users

 ___
 rspec-users mailing list
 rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Noob syntax questions regarding rspec book...

2009-07-08 Thread internetchris
In addition - Ben thanks for the link, I just checked it out.  Rubular
seems like an awesome little tool and I will bookmark the page. I
really appreciate all of the help and hope I can return the favor one
day.

Thanks!

Chris

On Jul 8, 10:43 pm, internetchris ch...@silhouettesolutions.net
wrote:
 Hey everyone,

 I appreciate the replies. After I posted I realized I was looking at
 ruby code. It seems this is where my learning curve is going to take a
 leap. I understand Rails, I am starting to understand Rspec and
 Cucumber, and I understand programming. This is my second language,
 but it's the first time I have had to learn something new. I come from
 a foxpro background and it seems I need to dig into the Ruby language
 a little more. I keep forgetting that Rails is simply a framework and
 not the language - the same is true for Rspec. I hope to laugh at my
 mistakes in a year or two :-)

 Thanks!

 Chris Sund

 On Jul 7, 9:49 am, ssmithstone stephen.smithst...@gmail.com wrote:

  I to am in the same situation and the meaning of the /^ $/ is a
  regular expression so it matches yours features so in your features is
  you do

  Give some random text I guess some more random test

  the code would run against that given method, hope that makes sense
  and that's my view of the code

  On Jul 7, 4:35 pm, Chris Sund ch...@silhouettesolutions.net wrote:

   Hey Everyone,

   I've been working my way through the Rspec book trying to absorb and
   understand everything. This is my first time with BDD and I'm just
   trying to figure out some simple syntax stuff. My questions revolve
   around some of the syntaxing used in the book. These are really simple
   questions.

   1.) Given /^the secret code is (. . . .)$/ do |code|
           Is (. . . .) simply a place holder? could I use something like
   (- - - -) instead, or does it actually mean something?

   2.) Then /^the mark should be (.*)$/ do |mark|
           Similar questionwhat does .* represent?

   3.) In the following example why don't I pass   |guess| to the When
   statement? I'm sure it has something to do with the (code.split)
   syntax, I'm just not sure what.

   When /^I guess (. . . .)$/ do |code|
   @game.guess(code.split)
   end

   4.) And finally what does (\n) do?

   Then /^the mark should be (.*)$/ do |mark|
     @messenger.string.split(\n).should include(mark)
   end

   Thank You!

   Chris
   ___
   rspec-users mailing list
   rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users

  ___
  rspec-users mailing list
  rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users

 ___
 rspec-users mailing list
 rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Noob syntax questions regarding rspec book...

2009-07-07 Thread Yi Wen

They are regex.
On Jul 7, 2009, at 10:35 AM, Chris Sund wrote:


Hey Everyone,

I've been working my way through the Rspec book trying to absorb and
understand everything. This is my first time with BDD and I'm just
trying to figure out some simple syntax stuff. My questions revolve
around some of the syntaxing used in the book. These are really simple
questions.


1.) Given /^the secret code is (. . . .)$/ do |code|
   Is (. . . .) simply a place holder? could I use something like
(- - - -) instead, or does it actually mean something?

2.) Then /^the mark should be (.*)$/ do |mark|
   Similar questionwhat does .* represent?



3.) In the following example why don't I pass   |guess| to the When
statement? I'm sure it has something to do with the (code.split)
syntax, I'm just not sure what.

When /^I guess (. . . .)$/ do |code|
@game.guess(code.split)
end


4.) And finally what does (\n) do?

Then /^the mark should be (.*)$/ do |mark|
 @messenger.string.split(\n).should include(mark)
end





Thank You!

Chris
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Noob syntax questions regarding rspec book...

2009-07-07 Thread David Chelimsky
On Tue, Jul 7, 2009 at 10:35 AM, Chris
Sundch...@silhouettesolutions.net wrote:
 Hey Everyone,

 I've been working my way through the Rspec book trying to absorb and
 understand everything. This is my first time with BDD and I'm just
 trying to figure out some simple syntax stuff. My questions revolve
 around some of the syntaxing used in the book. These are really simple
 questions.

Hey Chris,

The book assumes a basic working knowledge of Ruby. The questions you
are asking are about Ruby, not about RSpec or Cucumber. I'll answer
them for you here, but I don't think this is appropriate or necessary
for the book itself.

 1.) Given /^the secret code is (. . . .)$/ do |code|
        Is (. . . .) simply a place holder? could I use something like
 (- - - -) instead, or does it actually mean something?

The argument to Given is a regular expression. The . means any
character, so (. . . .) means any four characters with spaces in
between. There are certainly more specific and fool-proof ways we
could express this, but this is a very simple way, and works just fine
in the context of a cucumber step definition.

 2.) Then /^the mark should be (.*)$/ do |mark|
        Similar questionwhat does .* represent?

The . means any character and the * means any number of times.

 3.) In the following example why don't I pass   |guess| to the When
 statement? I'm sure it has something to do with the (code.split)
 syntax, I'm just not sure what.

 When /^I guess (. . . .)$/ do |code|
 @game.guess(code.split)
 end

You're correct - code.split converts r y g c to ['r', 'y', 'g',
'c'], which is what the game wants to receive (an array, rather than a
string).

 4.) And finally what does (\n) do?

 Then /^the mark should be (.*)$/ do |mark|
 �...@messenger.string.split(\n).should include(mark)
 end

The @messenger is a StringIO object. It receives puts() statements and
adds them to it's string attribute with a line break (\n) at the end
so if you do this:

@messenger.puts a
@messenger.puts b

Then the result of @messenger.string is a\nb\n

Splitting that on \n results in [a,b], which allows you to ask
if that result includes a, for example:

  @messenger.split(\n).include?(a)

Which can be expressed as an expectation in RSpec like this:

  @messenger.split(\n).should include(a)


HTH,
David






 Thank You!

 Chris
 ___
 rspec-users mailing list
 rspec-users@rubyforge.org
 http://rubyforge.org/mailman/listinfo/rspec-users

___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Noob syntax questions regarding rspec book...

2009-07-07 Thread Rick DeNatale
On Tue, Jul 7, 2009 at 11:35 AM, Chris
Sundch...@silhouettesolutions.net wrote:
 Hey Everyone,

 I've been working my way through the Rspec book trying to absorb and
 understand everything. This is my first time with BDD and I'm just
 trying to figure out some simple syntax stuff. My questions revolve
 around some of the syntaxing used in the book. These are really simple
 questions.


 1.) Given /^the secret code is (. . . .)$/ do |code|
        Is (. . . .) simply a place holder? could I use something like
 (- - - -) instead, or does it actually mean something?

Yes it actually means something. the stuff between // is a regular
expression, and some of the characters have meaning.

   ^ means the beginning of the string
   $ means the end of the string
   Each . will mark a single character, any character will do.
  The parens mark a group, the part of the string which marks the
group will be assigned to the code parameter.
  So when the whole regex matches code will be set to the four
characters of the code separated by spaces.

 2.) Then /^the mark should be (.*)$/ do |mark|
        Similar questionwhat does .* represent?

it means zero or more arbitrary characters

 3.) In the following example why don't I pass   |guess| to the When
 statement? I'm sure it has something to do with the (code.split)
 syntax, I'm just not sure what.

 When /^I guess (. . . .)$/ do |code|
 @game.guess(code.split)
 end

There isn't a variable named guess here. As I said in answer to the
first question, if the story says

When I guess 1 3 4 2

then when the step is executed the code parameter to the block will be
set to 1 3 4 2 and 1 3 4 2.split gives [1, 3, 4, 2]
 4.) And finally what does (\n) do?

 Then /^the mark should be (.*)$/ do |mark|
 �...@messenger.string.split(\n).should include(mark)
 end

\n is a ruby string literal representing a new-line, so
   @messenger.string.split(\n) results in an array comprising each
line within @messenger.string



-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Noob syntax questions regarding rspec book...

2009-07-07 Thread Ben Mabey

Rick DeNatale wrote:

On Tue, Jul 7, 2009 at 11:35 AM, Chris
Sundch...@silhouettesolutions.net wrote:
  

Hey Everyone,

I've been working my way through the Rspec book trying to absorb and
understand everything. This is my first time with BDD and I'm just
trying to figure out some simple syntax stuff. My questions revolve
around some of the syntaxing used in the book. These are really simple
questions.


1.) Given /^the secret code is (. . . .)$/ do |code|
   Is (. . . .) simply a place holder? could I use something like
(- - - -) instead, or does it actually mean something?



Yes it actually means something. the stuff between // is a regular
expression, and some of the characters have meaning.

   ^ means the beginning of the string
   $ means the end of the string
   Each . will mark a single character, any character will do.
  The parens mark a group, the part of the string which marks the
group will be assigned to the code parameter.
  So when the whole regex matches code will be set to the four
characters of the code separated by spaces.
  

2.) Then /^the mark should be (.*)$/ do |mark|
   Similar questionwhat does .* represent?



it means zero or more arbitrary characters

  

3.) In the following example why don't I pass   |guess| to the When
statement? I'm sure it has something to do with the (code.split)
syntax, I'm just not sure what.

When /^I guess (. . . .)$/ do |code|
@game.guess(code.split)
end



There isn't a variable named guess here. As I said in answer to the
first question, if the story says

When I guess 1 3 4 2

then when the step is executed the code parameter to the block will be
set to 1 3 4 2 and 1 3 4 2.split gives [1, 3, 4, 2]
  

4.) And finally what does (\n) do?

Then /^the mark should be (.*)$/ do |mark|
 @messenger.string.split(\n).should include(mark)
end



\n is a ruby string literal representing a new-line, so
   @messenger.string.split(\n) results in an array comprising each
line within @messenger.string



  



Chris,
FYI, a good resource to learn and play around with reg exps in ruby is: 
http://rubular.com/


-Ben
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Noob syntax questions regarding rspec book...

2009-07-07 Thread ssmithstone
I to am in the same situation and the meaning of the /^ $/ is a
regular expression so it matches yours features so in your features is
you do

Give some random text I guess some more random test

the code would run against that given method, hope that makes sense
and that's my view of the code

On Jul 7, 4:35 pm, Chris Sund ch...@silhouettesolutions.net wrote:
 Hey Everyone,

 I've been working my way through the Rspec book trying to absorb and
 understand everything. This is my first time with BDD and I'm just
 trying to figure out some simple syntax stuff. My questions revolve
 around some of the syntaxing used in the book. These are really simple
 questions.

 1.) Given /^the secret code is (. . . .)$/ do |code|
         Is (. . . .) simply a place holder? could I use something like
 (- - - -) instead, or does it actually mean something?

 2.) Then /^the mark should be (.*)$/ do |mark|
         Similar questionwhat does .* represent?

 3.) In the following example why don't I pass   |guess| to the When
 statement? I'm sure it has something to do with the (code.split)
 syntax, I'm just not sure what.

 When /^I guess (. . . .)$/ do |code|
 @game.guess(code.split)
 end

 4.) And finally what does (\n) do?

 Then /^the mark should be (.*)$/ do |mark|
   @messenger.string.split(\n).should include(mark)
 end

 Thank You!

 Chris
 ___
 rspec-users mailing list
 rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users