SlideShare uma empresa Scribd logo
1 de 6
Baixar para ler 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque (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
 

Semelhante a 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.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
 
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
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
Wen-Tien Chang
 

Semelhante a 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
 

Mais de 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
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
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
 

Mais de 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
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
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
Safe Software
 

Último (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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, ...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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...
 

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