Everyday Scripting with Ruby: For Teams, Testers, and You
Format: PDF / Kindle (mobi) / ePub
Are you a tester who spends more time manually creating complex test data than using it? A business analyst who seemingly went to college all those years so you can spend your days copying data from reports into spreadsheets? A programmer who can't finish each day's task without having to scan through version control system output, looking for the file you want?
If so, you're wasting that computer on your desk. Offload the drudgery to where it belongs, and free yourself to do what you should be doing: thinking. All you need is a scripting language (free!), this book (cheap!), and the dedication to work through the examples and exercises.
Everyday Scripting with Ruby is divided into four parts. In the first, you'll learn the basics of the Ruby scripting language. In the second, you'll see how to create scripts in a steady, controlled way using test-driven design. The third part is about finding, understanding, and using the work of others--and about preparing your scripts for others to use. The fourth part, more advanced, is about saving even more time by using application frameworks.
A.rb, which would load B.rb. . . . Given require, why ever use load? Suppose you’re writing some code in a file. You require it into irb and try it. Oops, it’s wrong. You change the file. If you require it again, you won’t get the changed version (because Ruby knows you’ve already loaded that file). You have to use load to get the new version. So use require in script files and load in irb. Time.now is used as the argument to month_before, but the test doesn’t have to use a Time that
page 98. 4. 81 B UILDING A S OLUTION It takes advantage of Ruby’s string multiplication. Like multiplication of integers, it’s just shorthand for adding the same thing multiple times. So ’*’ * 5 is the same as ’*’ + ’*’ + ’*’ + ’*’ + ’*’ and ’*****’. What should happen when the change count is not evenly divisible by five? It should round: Download churn/snapshots/churn-tests.v4.rb def test_asterisks_for_rounds_up_and_down assert_equal('****' , asterisks_for(18)) assert_equal('***' ,
useful to distinguish between the methods belonging to a class and the methods belonging to its instances. So, in the case of MyClass, we say that new is a class method and name is an instance method. You can define your own class methods like this: class method instance method irb(main):144:0> class AnyOldClass irb(main):145:1> def self.class_method irb(main):146:2> "I am a class method." irb(main):147:2> end irb(main):148:1> end The self indicates that the method is to be defined for the
Scripting with Ruby For Teams, Testers, and You Brian Marick The Pragmatic Bookshelf Raleigh, North Carolina Dallas, Texas Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic
messages, and telling an object to do something is called sending a message. You don’t have direct access to the objects inside the Ruby universe. To get at one of them, you have to use a name that refers to it. It’s similar in our universe: I am an object. My children refer to me as “Dad,” my wife refers to me as “hubster” or even more embarrassing names, and a clerk at the Philadelphia airport referred to me as “31” and “hey, you.” All of them used names to talk about the object that is me.