Donnerstag, 21. Oktober 2010
Woooha. Real BDD using rspec in real life!
hi there...
long time no see. Well, I did continue with my learning tests but that's nothing that might be interesting for anyone except me...
But today I learned new stuff
a) there is no 1.9 ruby for cygwin (yet). I use v1.8.7 :-(
b) I cant use this
inst_section = {
cello: 'string'
clarinet: 'woodwind',
...
}
This is the new feature "New literal hash syntax" in ruby. See http://svn.ruby-lang.org/repos/ruby/tags/v1_9_1_0/NEWS
d) also have a look here: http://www.ruby-lang.org/de/news/2009/02/01/ruby-1-9-1-verffentlicht/ and here: http://www.ruby-lang.org/de/news/2010/08/24/ruby-1-9-2-verffentlicht/
But the coolest part I stubled across when I looked for v1.8 / v1.9 differences: http://www.rubyspec.org/ These guys are using rubys rspec to write a (or maybe _the_) comprehensive ruby spec! As executable BDD code! COOL!.
Wanna see an example of the spec? Have a look here, even I a am still on page #21 in my ruby bible I am able to understand this spec! Great, imagin every business analyst would write such a spec!!! http://github.com/rubyspec/rubyspec/blob/master/core/array/flatten_spec.rb
Montag, 4. Oktober 2010
what would I have done without a book? Let's praise Mr. Gutenberg...
Yeah, I got my book. And learning this way is muuuuch more efficient compared to googling and reading the spec :) For now the most relevant and new aspects for me were
[Thomas, p15]
ruby is "genuine" object-oriented language. For instance
num = -1234 // Java code
abs = Math.abs(num) // abs is 1234
num = -1234 # ruby code
abs = num.abs # abs is 1234
# abs() is called on num! Not on Math
[Thomas, p16]
puts say_goodnight("John-Boy")
puts(say_goodnight("John-Boy"))
--> both lines are equivalent
--> precedence rules can make it difficult to know which argument goes with wich method invocation
--> so we recommend using parantheses in all but the simplest cases
But I also spent some time browsing the www. Focus this time: BDD. Have a look here: http://blog.dannorth.net/introducing-bdd/
and here: http://blog.davidchelimsky.net/2007/05/14/an-introduction-to-rspec-part-i/
[Thomas, p15]
ruby is "genuine" object-oriented language. For instance
num = -1234 // Java code
abs = Math.abs(num) // abs is 1234
num = -1234 # ruby code
abs = num.abs # abs is 1234
# abs() is called on num! Not on Math
[Thomas, p16]
puts say_goodnight("John-Boy")
puts(say_goodnight("John-Boy"))
--> both lines are equivalent
--> precedence rules can make it difficult to know which argument goes with wich method invocation
--> so we recommend using parantheses in all but the simplest cases
But I also spent some time browsing the www. Focus this time: BDD. Have a look here: http://blog.dannorth.net/introducing-bdd/
and here: http://blog.davidchelimsky.net/2007/05/14/an-introduction-to-rspec-part-i/
Sonntag, 26. September 2010
using a config file
Yesterday I noticed that I will need a config file. For instance if I want to call a dos command like srvrmgr.exe (Siebel ServerManager) I need to be able to configure the path to srvrmgr.exe. Also there might be more then one srvrmgr.exe binaries around and I need to make sure the right one is executed...
After short time of googling "ruby read config file" and some other keywords the decision was obvious: I will use YAML [ToDo: learn YAML]
http://www.5dollarwhitebox.org/drupal/?q=node/21
--> does not seem to be sophisticated
--> what?!? No tests, only "# FIX ME AND WRITE TESTS" in "test_parse_config.rb". No way I will use this hack...
http://otype.de/index.php?id=151
--> straigthforward, should work
--> but most probably not powerfull enough for more tricky demands
http://blog.innovativethought.net/2007/07/25/making-configuration-files-with-yaml/
http://yaml.kwiki.org/?YamlInFiveMinutes
http://www.yaml.org/YAML_for_ruby.html
--> if YAML is so easy, I don't see any reason not to use it
--> and learning YAML is a must for rails anyhow (afaik)
After short time of googling "ruby read config file" and some other keywords the decision was obvious: I will use YAML [ToDo: learn YAML]
http://www.5dollarwhitebox.org/drupal/?q=node/21
--> does not seem to be sophisticated
--> what?!? No tests, only "# FIX ME AND WRITE TESTS" in "test_parse_config.rb". No way I will use this hack...
http://otype.de/index.php?id=151
--> straigthforward, should work
--> but most probably not powerfull enough for more tricky demands
http://blog.innovativethought.net/2007/07/25/making-configuration-files-with-yaml/
http://yaml.kwiki.org/?YamlInFiveMinutes
http://www.yaml.org/YAML_for_ruby.html
--> if YAML is so easy, I don't see any reason not to use it
--> and learning YAML is a must for rails anyhow (afaik)
Freitag, 24. September 2010
STDOUT, STDERR, STDIN
this time I started to work with STDOUT, STDERR, STDIN. Handy that there is a class which handles all this for me: open3: http://ruby-doc.org/stdlib/libdoc/open3/rdoc/index.html
While doing so I came along this piece of code:
stdin, stdout, stderr = popen3('pwd')
a = stdout.readlines()
And I started asking myself if there is a difference between
assert_equal("/cygdrive/d/BACKUP~1/SMG\n", a.to_s, 'using readlines to squeeze stdout into a string, with braces')
assert_equal "/cygdrive/d/BACKUP~1/SMG\n", a.to_s, 'using readlines to squeeze stdout into a string,
without braces'
I did not find an answer yet, hence a new todo was born: [ToDo: find out if there is a difference between function calls with or without braces]
What I did find out was that there are differences between strings and symbols: Have a look here: http://www.robertsosinski.com/2009/01/11/the-difference-between-ruby-symbols-and-strings/
What I also did find out was that there is a difference between "a String" and "an other String". Have a look here: http://en.wikibooks.org/wiki/Ruby_Programming/Strings#Interpolation
Donnerstag, 23. September 2010
tadaaaaa: my first unit tests
Now its time to get started. I wanna write some code. As mentioned before, I consider having tests as a MUST. Hence I will use Test::Unit from the first minute on. But how and where to start?
Of course the official reference helps: http://www.ruby-doc.org/core/classes/Test/Unit.html
Further on I had to have a short look what modules are about (I have to admit the "Test::Unit" notation reminded me far to much of PERL...) Look here: http://www.rubyfleebie.com/an-introduction-to-modules-part-1/ and here:
http://www.rubyfleebie.com/an-introduction-to-modules-part-2/
And the most important help for me was this tiny little post: But http://www.clarkware.com/cgi/blosxom/2005/03/18/RLT1 I really like the idea of just testing what the ruby language offers. Why reading books when you can play. Well, not poking around only, the combination of reading the specs and then trying/testing whether or not I got everything right is cool!
Result: I committed my first unit test to GitHub: http://github.com/SlevinMcGuigan/SMG--learn :-D :-D :-D
Of course the official reference helps: http://www.ruby-doc.org/core/classes/Test/Unit.html
Further on I had to have a short look what modules are about (I have to admit the "Test::Unit" notation reminded me far to much of PERL...) Look here: http://www.rubyfleebie.com/an-introduction-to-modules-part-1/ and here:
http://www.rubyfleebie.com/an-introduction-to-modules-part-2/
And the most important help for me was this tiny little post: But http://www.clarkware.com/cgi/blosxom/2005/03/18/RLT1 I really like the idea of just testing what the ruby language offers. Why reading books when you can play. Well, not poking around only, the combination of reading the specs and then trying/testing whether or not I got everything right is cool!
Result: I committed my first unit test to GitHub: http://github.com/SlevinMcGuigan/SMG--learn :-D :-D :-D
yeah, now I got a wiki :)
well, after short googling I decided to use wikispaces.com. I tried some features in the sandbox and this is much more convenient compared to Google Sites. Very, very much more!
Here we go, this is my wiki: http://slevinmcguigan.wikispaces.com/
Further on I started with git and signed on at github.com. After creating my public/private key pair I played around. Here comes the link to my github sources, a good-to-know gitref link and some git commands I consider most important
http://github.com/SlevinMcGuigan/SMG--ExecShellCommand
http://gitref.org/remotes/
git config --global user.name "Slevin McGuigan"
git config --global user.email "Slevin.McGuigan@googlemail.com"
git init
git add README
git commit -m 'first commit'
git remote add github git@github.com:SlevinMcGuigan/SMG--ExecShellCommand
git push github master
... some changes on README and README.txt ...
git add README.txt
git commit -m 'added hello world - attempt 3'
git push github master
Here we go, this is my wiki: http://slevinmcguigan.wikispaces.com/
Further on I started with git and signed on at github.com. After creating my public/private key pair I played around. Here comes the link to my github sources, a good-to-know gitref link and some git commands I consider most important
http://github.com/SlevinMcGuigan/SMG--ExecShellCommand
http://gitref.org/remotes/
git config --global user.name "Slevin McGuigan"
git config --global user.email "Slevin.McGuigan@googlemail.com"
git init
git add README
git commit -m 'first commit'
git remote add github git@github.com:SlevinMcGuigan/SMG--ExecShellCommand
git push github master
... some changes on README and README.txt ...
git add README.txt
git commit -m 'added hello world - attempt 3'
git push github master
Montag, 20. September 2010
me vs. google sites
Oh my god! I just wanted a tiny little To-Do list. Maintainable and editable like a wiki using wiki-markup (or something similar).
I tried...
I tried harder...
I fought...
...
I lost... :(
Although Google says "Erstellen Sie Websites und sichere Gruppen-Wikis" I neither managed to set up a simple (and more-or-less eye-friendly) website nor to set up a simple wiki. Grrrrrrrr!
I tried...
I tried harder...
I fought...
...
I lost... :(
Although Google says "Erstellen Sie Websites und sichere Gruppen-Wikis" I neither managed to set up a simple (and more-or-less eye-friendly) website nor to set up a simple wiki. Grrrrrrrr!
Abonnieren
Posts (Atom)