SlideShare a Scribd company logo
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 AngularJS
Jim Lynch
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
noelrap
 
Jasmine BDD for Javascript
Jasmine BDD for JavascriptJasmine BDD for Javascript
Jasmine BDD for Javascript
Luis Alfredo Porras Páez
 
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
foxp2code
 
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
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
Dr. Syed Hassan Amin
 
Test your tests with PIT framework
Test your tests with PIT frameworkTest your tests with PIT framework
Test your tests with PIT framework
Darko Špoljarić
 
Continuous integration with Git & CI Joe
Continuous integration with Git & CI JoeContinuous integration with Git & CI Joe
Continuous integration with Git & CI Joe
Shawn Price
 
Anatomy of a Gem: Bane
Anatomy of a Gem: BaneAnatomy of a Gem: Bane
Anatomy of a Gem: Bane
Daniel 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 minutes
Paulo 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
 
Integration testing
Integration testingIntegration testing
Integration testing
Tsegabrehan Am
 
Intro to front-end testing
Intro to front-end testingIntro to front-end testing
Intro to front-end testing
Juriy 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...
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
 
Test your tests with PIT framework
Test your tests with PIT frameworkTest your tests with PIT framework
Test your tests with PIT framework
 
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

collapsible-panels-tutorial
collapsible-panels-tutorialcollapsible-panels-tutorial
collapsible-panels-tutorial
tutorialsruby
 
Ad-journal
Ad-journalAd-journal
Ad-journal
tutorialsruby
 
INFS730
INFS730INFS730
INFS730
tutorialsruby
 
tutorial2-notes2
tutorial2-notes2tutorial2-notes2
tutorial2-notes2
tutorialsruby
 
hw4_specifications
hw4_specificationshw4_specifications
hw4_specifications
tutorialsruby
 
newsletter84
newsletter84newsletter84
newsletter84
tutorialsruby
 

Viewers also liked (6)

collapsible-panels-tutorial
collapsible-panels-tutorialcollapsible-panels-tutorial
collapsible-panels-tutorial
 
Ad-journal
Ad-journalAd-journal
Ad-journal
 
INFS730
INFS730INFS730
INFS730
 
tutorial2-notes2
tutorial2-notes2tutorial2-notes2
tutorial2-notes2
 
hw4_specifications
hw4_specificationshw4_specifications
hw4_specifications
 
newsletter84
newsletter84newsletter84
newsletter84
 

Similar to wtst3_pettichord3

RubyTesting
RubyTestingRubyTesting
RubyTesting
tutorialsruby
 
RubyTesting
RubyTestingRubyTesting
RubyTesting
tutorialsruby
 
Ansible testing
Ansible   testingAnsible   testing
Ansible testing
Scott van Kalken
 
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
annettsparrow
 
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
webhostingguy
 
Instant DBMS Homework Help
Instant DBMS Homework HelpInstant DBMS Homework Help
Instant DBMS Homework Help
Database Homework Help
 
Rspec
RspecRspec
Database Management Assignment Help
Database Management Assignment Help Database Management Assignment Help
Database Management Assignment Help
Database Homework Help
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# Developers
Cory 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 Development
Rabble .
 
Rtt preso
Rtt presoRtt preso
Rtt preso
fdschoeneman
 
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
 
Test Driven
Test DrivenTest Driven
Test Driven
Alex Chaffee
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdf
Eric 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.docx
DIPESH30
 
LecccccccccccccProgrammingLecture-09.pdf
LecccccccccccccProgrammingLecture-09.pdfLecccccccccccccProgrammingLecture-09.pdf
LecccccccccccccProgrammingLecture-09.pdf
AmirMohamedNabilSale
 
Unit testing
Unit testingUnit testing
Unit testing
DrSimoneDiCola
 
Test Coverage in Rails
Test Coverage in RailsTest Coverage in Rails
Test Coverage in Rails
James Gray
 
Speed up rspec tests - part 1
Speed up rspec tests - part 1Speed up rspec tests - part 1
Speed up rspec tests - part 1
Railwaymen
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
Wen-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 – INS0
tutorialsruby
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
tutorialsruby
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
tutorialsruby
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
tutorialsruby
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
tutorialsruby
 
CSS
CSSCSS
CSS
CSSCSS
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
tutorialsruby
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 

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

Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 

Recently uploaded (20)

Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 

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