SlideShare a Scribd company logo
1 of 6
Download to read offline
Lab 1: Playing with the Timeclock command line
Please note that you also have a Timeclock Cheat Sheet in your course packet.

Try some free-form fun with the timeclock interface. Try out different commands. Spend
some time making mistakes. What happens if you try to stop a job that wasn't started?
Start a job that doesn't exist?
As you type along, you'll likely make some different kinds of mistakes:
   •   You might forget quotes where they're needed.
   •   You might leave out a comma that's required.
   •   You might mistype a command name.
Some of those mistakes will produce much less pleasant error messages than the ones
from the mistakes in the first paragraph. You'll learn more about the "why" behind those
messages later. For now, just don’t be alarmed when you see them. In fact, spend a little
time going out of your way to cause them. Save up the error messages and make sure that
you understand them by the end of the day (getting us to explain them, if necessary).




Copyright © 2003 by Brian Marick and Bret Pettichord. All rights reserved.
Lab 2: Testing command results
As you just saw, your tests will use the utility function assert_equal. Where is it on
your computer? We're going to be mean and make you type it in. (That's because we
believe most people learn a language fastest when they start typing in it, not when they
watch other people type. So typing this definition will help you understand it.
Put the following in a file called asserts.rb.
        def assert_equal(expected, actual)
          if expected != actual
            puts "FAILURE: Expected <#{expected}>, but was <#{actual}>."
          end
        end
At this point, you could do one of two things. You could believe you typed everything
correctly and proceed to testing Timeclock. Or you could check. We recommend
checking.
One of the nice things about languages, like Ruby, that have interpreters is that they make
it easy to check things like that. Use start.bat to start up the Ruby interpreter. Do it
in the same directory you created asserts.rb. Then type this:
        load 'asserts.rb'1
        assert_equal('hi', 'hi')
        assert_equal('hi', 'there')
Does the first one succeed (print nothing)? Does the second one fail? If something odd
happens, try to figure out where you made a mistake, and don't hesitate to ask for help.


Now that you trust asserts.rb, create your test file. Call it test.rb. It should start
out looking like this:
        require 'loadable-timeclock'
        require 'asserts'
Now you can add your tests after those lines, like this:
        assert_equal("Job 'timeclock' created.", job('timeclock'))
Run the tests like this:
        C:tutorial> ruby test.rb
Try some more tests of the job command. After a while, we suggest you try the start
command. You should quickly run into a problem testing. That'll be a good time for us to
stop and discuss something new, regular expressions. Then we'll resume the lab.

1
  What's load? What happened to require? The main difference is that load always
loads the file named, but require only loads it once. Later, you're going to change
asserts.rb. You might want to try those changes in the interpreter, which you might
have left running. To load the new version, you have to use load, so you might as well
use it here.

Lab instructions                             2
After the lab resumes, you'll want to add this to asserts.rb:
       def assert_match(expected_regex, actual_string)
        unless expected_regex =~ actual_string
         puts "FAILURE: Expected <#{actual_string}> to match <#{expected_regex.inspect}>."
        end
       end




Lab instructions                               3
Lab 3: Test::Unit
Your job here is just to explore the Test::Unit framework. You'll be using it more later.
Start by changing the beginning of your test.rb file to require test/unit instead of
asserts.rb:
       require 'test/unit'
Next, "wrap" the following around your test statements:
       class TimeclockTests < Test::Unit::TestCase
         def test_job
           all your test statements go here
         end
       end
Run that (ruby test.rb). See if it works.
Now play around with your tests. Try tests that fail. What happens to assert_equal
statements after the failure? Are they tried? (The output says how many assertions were
tried. Is it different in the case of failure?)
Try splitting your tests into several different functions (methods). In what order are tests
run?
What if one of the function's names doesn't start with "test"? Of what use could such a
function be?




Lab instructions                              4
Lab 4: Two new classes
Begin by walking through the examples for Arrays and Hashes in the Ruby Cheat Sheet
(approximately pages 4 and 5).
"Walk through?" That means use the Ruby interpreter to type those expressions. As we've
seen, the Timeclock program is a ruby interpreter. But it's a slightly modified one, one
that prints results in a way that won't be useful for this lab. (It doesn't show the quotes
around strings or the braces around arrays and hashes.)
So start the interpreter by typing irb at your command prompt. Now go to page 4 of the
Ruby Cheat Sheet.


Now try a few other things.
   1. Put arrays inside arrays. For example, how would you convert [1, 2] to
      [ ['hi'], 2, ['you', 'and me'] ] ?
   2. If the above array is the value of variable array, what's the value of
      array[0]? What's the value of array[0][0]?

       What's the value of array.last? Of array.last.last?
   3. Make a dictionary that associates 'bret' with 'texas' and 'brian' with
      'illinois'. Have the variable states refer to it.

       Make an empty array.

       How can you put the dictionary into the array?

       Once you've got it there, what's an expression that shows Bret's home state?

       Have the variable instructors refer to this array: ['bret', 'brian'].
       (Can you get that array from the dictionary states?) Write an expression that
       tells you in what state the second instructor lives.




Lab instructions                            5
Lab 5: Web Services
The Timeclock Web Services Interface defines the different messages that the server
accepts. You've seen several of them demonstrated already.

Improving the sample tests
You just finished seeing a demonstration of creating two tests. You can find something
close to those tests in web-test.rb.
Consider the first test. It's kind of inadequate, since start does more than just create a
record:
   •   It's supposed to start the job running. You can check that with
       session.running?('star').
   •   The record start creates is supposed to contain the job it's for. That job's name
       had better be the same string as the argument to start. You can get the record's
       job with record.job and the job's name with job.name.
   •   start is supposed to return the job it started. That job had better be named
       'star'.
Update the test to check whether all these things that are supposed to be true are.
Then update the second test to check that an incorrect starting-of-a-started-job leaves
alone things it should leave alone (like whether 'star' is running).

Run wild!
The Timeclock Web Services Interface document defines a number of timeclock
commands. They should seem familiar because most of them straightforwardly
correspond to command-line commands. Write tests for them.
It's probably easiest to write tests for various combinations of starting, pausing, and
stopping jobs. Check records and which jobs are running. Write utility functions as you
find them useful.
Try lots of different things. Ask questions when you want to do something but don't
know how.




Lab instructions                             6

More Related Content

What's hot

Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSJim Lynch
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everythingnoelrap
 
AngularJS Unit Testing w/Karma and Jasmine
AngularJS Unit Testing w/Karma and JasmineAngularJS Unit Testing w/Karma and Jasmine
AngularJS Unit Testing w/Karma and Jasminefoxp2code
 
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...Samyak Bhalerao
 
Test your tests with PIT framework
Test your tests with PIT frameworkTest your tests with PIT framework
Test your tests with PIT frameworkDarko Špoljarić
 
Continuous integration with Git & CI Joe
Continuous integration with Git & CI JoeContinuous integration with Git & CI Joe
Continuous integration with Git & CI JoeShawn Price
 
Anatomy of a Gem: Bane
Anatomy of a Gem: BaneAnatomy of a Gem: Bane
Anatomy of a Gem: BaneDaniel Wellman
 
Async-await best practices in 10 minutes
Async-await best practices in 10 minutesAsync-await best practices in 10 minutes
Async-await best practices in 10 minutesPaulo Morgado
 
Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)jaxLondonConference
 
Intro to front-end testing
Intro to front-end testingIntro to front-end testing
Intro to front-end testingJuriy Zaytsev
 

What's hot (13)

Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
 
Jasmine BDD for Javascript
Jasmine BDD for JavascriptJasmine BDD for Javascript
Jasmine BDD for Javascript
 
AngularJS Unit Testing w/Karma and Jasmine
AngularJS Unit Testing w/Karma and JasmineAngularJS Unit Testing w/Karma and Jasmine
AngularJS Unit Testing w/Karma and Jasmine
 
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...
 
Test your tests with PIT framework
Test your tests with PIT frameworkTest your tests with PIT framework
Test your tests with PIT framework
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
 
Continuous integration with Git & CI Joe
Continuous integration with Git & CI JoeContinuous integration with Git & CI Joe
Continuous integration with Git & CI Joe
 
Anatomy of a Gem: Bane
Anatomy of a Gem: BaneAnatomy of a Gem: Bane
Anatomy of a Gem: Bane
 
Async-await best practices in 10 minutes
Async-await best practices in 10 minutesAsync-await best practices in 10 minutes
Async-await best practices in 10 minutes
 
Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)
 
Integration testing
Integration testingIntegration testing
Integration testing
 
Intro to front-end testing
Intro to front-end testingIntro to front-end testing
Intro to front-end testing
 

Viewers also liked

Viewers also liked (7)

has_many_and_belongs_to_many
has_many_and_belongs_to_manyhas_many_and_belongs_to_many
has_many_and_belongs_to_many
 
Accessing_MySQL_from_Ruby
Accessing_MySQL_from_RubyAccessing_MySQL_from_Ruby
Accessing_MySQL_from_Ruby
 
lab56_db
lab56_dblab56_db
lab56_db
 
ruby-efl-tutorial-hsyl20
ruby-efl-tutorial-hsyl20ruby-efl-tutorial-hsyl20
ruby-efl-tutorial-hsyl20
 
Devoxx%202008%20Tutorial
Devoxx%202008%20TutorialDevoxx%202008%20Tutorial
Devoxx%202008%20Tutorial
 
rails.html
rails.htmlrails.html
rails.html
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 

Similar to wtst3_pettichord3

CS 111 - Homework 5 p. 1CS 111 - Homework 5Deadline1.docx
CS 111 - Homework 5 p. 1CS 111 - Homework 5Deadline1.docxCS 111 - Homework 5 p. 1CS 111 - Homework 5Deadline1.docx
CS 111 - Homework 5 p. 1CS 111 - Homework 5Deadline1.docxannettsparrow
 
Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Frameworkwebhostingguy
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# DevelopersCory Foy
 
Beyond Testing: Specs and Behavior Driven Development
Beyond Testing: Specs and Behavior  Driven DevelopmentBeyond Testing: Specs and Behavior  Driven Development
Beyond Testing: Specs and Behavior Driven DevelopmentRabble .
 
mocha sinon chai Dc jquery 4-24
mocha sinon chai Dc jquery 4-24 mocha sinon chai Dc jquery 4-24
mocha sinon chai Dc jquery 4-24 Carson Banov
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfEric Selje
 
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docxLabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docxDIPESH30
 
LecccccccccccccProgrammingLecture-09.pdf
LecccccccccccccProgrammingLecture-09.pdfLecccccccccccccProgrammingLecture-09.pdf
LecccccccccccccProgrammingLecture-09.pdfAmirMohamedNabilSale
 
Test Coverage in Rails
Test Coverage in RailsTest Coverage in Rails
Test Coverage in RailsJames Gray
 
Speed up rspec tests - part 1
Speed up rspec tests - part 1Speed up rspec tests - part 1
Speed up rspec tests - part 1Railwaymen
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit TestingWen-Tien Chang
 

Similar to wtst3_pettichord3 (20)

RubyTesting
RubyTestingRubyTesting
RubyTesting
 
RubyTesting
RubyTestingRubyTesting
RubyTesting
 
Ansible testing
Ansible   testingAnsible   testing
Ansible testing
 
CS 111 - Homework 5 p. 1CS 111 - Homework 5Deadline1.docx
CS 111 - Homework 5 p. 1CS 111 - Homework 5Deadline1.docxCS 111 - Homework 5 p. 1CS 111 - Homework 5Deadline1.docx
CS 111 - Homework 5 p. 1CS 111 - Homework 5Deadline1.docx
 
Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Framework
 
Instant DBMS Homework Help
Instant DBMS Homework HelpInstant DBMS Homework Help
Instant DBMS Homework Help
 
Rspec
RspecRspec
Rspec
 
Database Management Assignment Help
Database Management Assignment Help Database Management Assignment Help
Database Management Assignment Help
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# Developers
 
Beyond Testing: Specs and Behavior Driven Development
Beyond Testing: Specs and Behavior  Driven DevelopmentBeyond Testing: Specs and Behavior  Driven Development
Beyond Testing: Specs and Behavior Driven Development
 
Rtt preso
Rtt presoRtt preso
Rtt preso
 
mocha sinon chai Dc jquery 4-24
mocha sinon chai Dc jquery 4-24 mocha sinon chai Dc jquery 4-24
mocha sinon chai Dc jquery 4-24
 
Test Driven
Test DrivenTest Driven
Test Driven
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdf
 
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docxLabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
 
LecccccccccccccProgrammingLecture-09.pdf
LecccccccccccccProgrammingLecture-09.pdfLecccccccccccccProgrammingLecture-09.pdf
LecccccccccccccProgrammingLecture-09.pdf
 
Unit testing
Unit testingUnit testing
Unit testing
 
Test Coverage in Rails
Test Coverage in RailsTest Coverage in Rails
Test Coverage in Rails
 
Speed up rspec tests - part 1
Speed up rspec tests - part 1Speed up rspec tests - part 1
Speed up rspec tests - part 1
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
 

More from tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

More from tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Recently uploaded

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 

wtst3_pettichord3

  • 1. Lab 1: Playing with the Timeclock command line Please note that you also have a Timeclock Cheat Sheet in your course packet. Try some free-form fun with the timeclock interface. Try out different commands. Spend some time making mistakes. What happens if you try to stop a job that wasn't started? Start a job that doesn't exist? As you type along, you'll likely make some different kinds of mistakes: • You might forget quotes where they're needed. • You might leave out a comma that's required. • You might mistype a command name. Some of those mistakes will produce much less pleasant error messages than the ones from the mistakes in the first paragraph. You'll learn more about the "why" behind those messages later. For now, just don’t be alarmed when you see them. In fact, spend a little time going out of your way to cause them. Save up the error messages and make sure that you understand them by the end of the day (getting us to explain them, if necessary). Copyright © 2003 by Brian Marick and Bret Pettichord. All rights reserved.
  • 2. Lab 2: Testing command results As you just saw, your tests will use the utility function assert_equal. Where is it on your computer? We're going to be mean and make you type it in. (That's because we believe most people learn a language fastest when they start typing in it, not when they watch other people type. So typing this definition will help you understand it. Put the following in a file called asserts.rb. def assert_equal(expected, actual) if expected != actual puts "FAILURE: Expected <#{expected}>, but was <#{actual}>." end end At this point, you could do one of two things. You could believe you typed everything correctly and proceed to testing Timeclock. Or you could check. We recommend checking. One of the nice things about languages, like Ruby, that have interpreters is that they make it easy to check things like that. Use start.bat to start up the Ruby interpreter. Do it in the same directory you created asserts.rb. Then type this: load 'asserts.rb'1 assert_equal('hi', 'hi') assert_equal('hi', 'there') Does the first one succeed (print nothing)? Does the second one fail? If something odd happens, try to figure out where you made a mistake, and don't hesitate to ask for help. Now that you trust asserts.rb, create your test file. Call it test.rb. It should start out looking like this: require 'loadable-timeclock' require 'asserts' Now you can add your tests after those lines, like this: assert_equal("Job 'timeclock' created.", job('timeclock')) Run the tests like this: C:tutorial> ruby test.rb Try some more tests of the job command. After a while, we suggest you try the start command. You should quickly run into a problem testing. That'll be a good time for us to stop and discuss something new, regular expressions. Then we'll resume the lab. 1 What's load? What happened to require? The main difference is that load always loads the file named, but require only loads it once. Later, you're going to change asserts.rb. You might want to try those changes in the interpreter, which you might have left running. To load the new version, you have to use load, so you might as well use it here. Lab instructions 2
  • 3. After the lab resumes, you'll want to add this to asserts.rb: def assert_match(expected_regex, actual_string) unless expected_regex =~ actual_string puts "FAILURE: Expected <#{actual_string}> to match <#{expected_regex.inspect}>." end end Lab instructions 3
  • 4. Lab 3: Test::Unit Your job here is just to explore the Test::Unit framework. You'll be using it more later. Start by changing the beginning of your test.rb file to require test/unit instead of asserts.rb: require 'test/unit' Next, "wrap" the following around your test statements: class TimeclockTests < Test::Unit::TestCase def test_job all your test statements go here end end Run that (ruby test.rb). See if it works. Now play around with your tests. Try tests that fail. What happens to assert_equal statements after the failure? Are they tried? (The output says how many assertions were tried. Is it different in the case of failure?) Try splitting your tests into several different functions (methods). In what order are tests run? What if one of the function's names doesn't start with "test"? Of what use could such a function be? Lab instructions 4
  • 5. Lab 4: Two new classes Begin by walking through the examples for Arrays and Hashes in the Ruby Cheat Sheet (approximately pages 4 and 5). "Walk through?" That means use the Ruby interpreter to type those expressions. As we've seen, the Timeclock program is a ruby interpreter. But it's a slightly modified one, one that prints results in a way that won't be useful for this lab. (It doesn't show the quotes around strings or the braces around arrays and hashes.) So start the interpreter by typing irb at your command prompt. Now go to page 4 of the Ruby Cheat Sheet. Now try a few other things. 1. Put arrays inside arrays. For example, how would you convert [1, 2] to [ ['hi'], 2, ['you', 'and me'] ] ? 2. If the above array is the value of variable array, what's the value of array[0]? What's the value of array[0][0]? What's the value of array.last? Of array.last.last? 3. Make a dictionary that associates 'bret' with 'texas' and 'brian' with 'illinois'. Have the variable states refer to it. Make an empty array. How can you put the dictionary into the array? Once you've got it there, what's an expression that shows Bret's home state? Have the variable instructors refer to this array: ['bret', 'brian']. (Can you get that array from the dictionary states?) Write an expression that tells you in what state the second instructor lives. Lab instructions 5
  • 6. Lab 5: Web Services The Timeclock Web Services Interface defines the different messages that the server accepts. You've seen several of them demonstrated already. Improving the sample tests You just finished seeing a demonstration of creating two tests. You can find something close to those tests in web-test.rb. Consider the first test. It's kind of inadequate, since start does more than just create a record: • It's supposed to start the job running. You can check that with session.running?('star'). • The record start creates is supposed to contain the job it's for. That job's name had better be the same string as the argument to start. You can get the record's job with record.job and the job's name with job.name. • start is supposed to return the job it started. That job had better be named 'star'. Update the test to check whether all these things that are supposed to be true are. Then update the second test to check that an incorrect starting-of-a-started-job leaves alone things it should leave alone (like whether 'star' is running). Run wild! The Timeclock Web Services Interface document defines a number of timeclock commands. They should seem familiar because most of them straightforwardly correspond to command-line commands. Write tests for them. It's probably easiest to write tests for various combinations of starting, pausing, and stopping jobs. Check records and which jobs are running. Write utility functions as you find them useful. Try lots of different things. Ask questions when you want to do something but don't know how. Lab instructions 6