From bc4bf7527160e3787db970a8d5e7f743bf677767 Mon Sep 17 00:00:00 2001 From: "Charles R. Owen" Date: Thu, 25 Feb 2016 22:57:45 -0500 Subject: [PATCH 1/8] Added rspec tests to ensure the result array contains correct number of elements. --- .../student-start/spec/lesson2_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Assignments/Lesson02-Assignment01-Collections/student-start/spec/lesson2_spec.rb b/Assignments/Lesson02-Assignment01-Collections/student-start/spec/lesson2_spec.rb index c7d00f9..01c8219 100644 --- a/Assignments/Lesson02-Assignment01-Collections/student-start/spec/lesson2_spec.rb +++ b/Assignments/Lesson02-Assignment01-Collections/student-start/spec/lesson2_spec.rb @@ -22,6 +22,15 @@ expect(n).to be >= 5000 } end + it "unexpected maximum number in array" do + expect(numbers.first).to be == 9999 + end + it "unexpected minimum number in array" do + expect(numbers.last).to be == 5001 + end + it "unexpected number of elements" do + expect(numbers.size).to be == (5001/3) + end it "not modulo 3" do numbers.each { |n| From eb93c2db82cf04589f24d7ac121e519703a35c30 Mon Sep 17 00:00:00 2001 From: "Charles R. Owen" Date: Thu, 25 Feb 2016 23:13:22 -0500 Subject: [PATCH 2/8] Added comments for the new rspec tests --- .../student-start/spec/lesson2_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Assignments/Lesson02-Assignment01-Collections/student-start/spec/lesson2_spec.rb b/Assignments/Lesson02-Assignment01-Collections/student-start/spec/lesson2_spec.rb index 01c8219..ac1e86a 100644 --- a/Assignments/Lesson02-Assignment01-Collections/student-start/spec/lesson2_spec.rb +++ b/Assignments/Lesson02-Assignment01-Collections/student-start/spec/lesson2_spec.rb @@ -22,14 +22,19 @@ expect(n).to be >= 5000 } end + # ensure that the first element in the array is 9999 it "unexpected maximum number in array" do expect(numbers.first).to be == 9999 end + # ensure that the last element in the array is 5001 + # remember every element in the array >= 5000 it "unexpected minimum number in array" do expect(numbers.last).to be == 5001 end + # ensure that the array contains the correct number of elements + # taking the last element and dividing by 3; 5001/3=1667 it "unexpected number of elements" do - expect(numbers.size).to be == (5001/3) + expect(numbers.size).to be == 1667 end it "not modulo 3" do From 3980cb1a29670e019f3189d202b9a46bfc171cca Mon Sep 17 00:00:00 2001 From: Kalman Hazins Date: Mon, 29 Feb 2016 17:57:35 -0500 Subject: [PATCH 3/8] Cleaned up the test code --- .../student-start/spec/lesson2_spec.rb | 72 +++++++------------ 1 file changed, 27 insertions(+), 45 deletions(-) diff --git a/Assignments/Lesson02-Assignment01-Collections/student-start/spec/lesson2_spec.rb b/Assignments/Lesson02-Assignment01-Collections/student-start/spec/lesson2_spec.rb index ac1e86a..12dbc74 100644 --- a/Assignments/Lesson02-Assignment01-Collections/student-start/spec/lesson2_spec.rb +++ b/Assignments/Lesson02-Assignment01-Collections/student-start/spec/lesson2_spec.rb @@ -3,73 +3,55 @@ describe "lesson2" do - context "check results" do - result=`ruby module2_lesson2_formative.rb` - lines=result.split("\n") - numbers=[] - #process the last line of output - values=lines[lines.count-1].split(",").each { |v| - number=/([0-9]+)/.match(v).to_s.to_i + context "output array" do + result = `ruby module2_lesson2_formative.rb` + lines = result.split("\n") + numbers = [] + + # process the last line of output + values = lines[lines.count-1].split(",").each { |v| + number = /([0-9]+)/.match(v).to_s.to_i numbers << number } - it "unexpected number of output lines" do + it "is expected to contain 3 lines" do expect(lines.size).to be == 3 end - it "unexpected minimum number" do + it "should not contain any number under 5000" do numbers.each { |n| expect(n).to be >= 5000 } end - # ensure that the first element in the array is 9999 - it "unexpected maximum number in array" do - expect(numbers.first).to be == 9999 - end - # ensure that the last element in the array is 5001 - # remember every element in the array >= 5000 - it "unexpected minimum number in array" do - expect(numbers.last).to be == 5001 - end - # ensure that the array contains the correct number of elements - # taking the last element and dividing by 3; 5001/3=1667 - it "unexpected number of elements" do - expect(numbers.size).to be == 1667 - end - it "not modulo 3" do - numbers.each { |n| - expect(n % 3).to be == 0 - } + it "is expected to be sorted in descending order" do + expect(numbers).to eq numbers.sort.reverse end - - it "unexpected sort order" do - lowest=nil - numbers.each { |n| - expect(n).to be <= lowest if !lowest.nil? - lowest=n - } + + it "should not contain numbers not divisible by 3" do + numbers.each do |n| + expect(n % 3).to be == 0 + end end end - #probably should strip out commented lines before doing this - context "check implementation" do - srcCode = File.open("module2_lesson2_formative.rb", "r").read + context "implementation" do + src_code = File.open("module2_lesson2_formative.rb", "r").read - it "missing select" do - expect(srcCode).to include("select") + it "should contain select" do + expect(src_code).to include("select") end - it "missing reject" do - expect(srcCode).to include("reject") + it "should contain reject" do + expect(src_code).to include("reject") end - it "missing sort" do - expect(srcCode).to include("sort") + it "should contain sort" do + expect(src_code).to include("sort") end - it "missing reverse" do - expect(srcCode).to include("reverse") + it "should contain reverse" do + expect(src_code).to include("reverse") end end end From 3c7e51baf02ec8636eb6afa27764c9ee7a3f5057 Mon Sep 17 00:00:00 2001 From: Joshua Shanks Date: Sat, 17 Sep 2016 10:09:02 -0700 Subject: [PATCH 4/8] Update readme to reflect current output --- .../README.html | 13 +++++++------ .../Lesson01-Assignment01-Case-Statement/README.md | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Assignments/Lesson01-Assignment01-Case-Statement/README.html b/Assignments/Lesson01-Assignment01-Case-Statement/README.html index 728a4f1..e2cccbd 100644 --- a/Assignments/Lesson01-Assignment01-Case-Statement/README.html +++ b/Assignments/Lesson01-Assignment01-Case-Statement/README.html @@ -63,18 +63,19 @@

Getting Started

  $ rspec
 
-.FFF
+.FFFF
 
 Failures:
 ...
 Finished in 0.02247 seconds (files took 0.1567 seconds to load)
-4 examples, 3 failures
+5 examples, 4 failures
 
 Failed examples:
 
-rspec ./spec/case_spec.rb:17 # lesson1 check implementation remove if clause
-rspec ./spec/case_spec.rb:21 # lesson1 check implementation remove elsif clause
-rspec ./spec/case_spec.rb:25 # lesson1 check implementation missing case
+rspec ./spec/lesson1_spec.rb:17 # lesson1 check implementation remove if clause +rspec ./spec/lesson1_spec.rb:21 # lesson1 check implementation remove elsif clause +rspec ./spec/lesson1_spec.rb:25 # lesson1 check implementation remove elsif clause +rspec ./spec/lesson1_spec.rb:29 # lesson1 check implementation missing case
  1. Implement the solution and re-test.
@@ -90,6 +91,6 @@

Self Grading/Feedback

$ rspec
 
 Finished in 0.00304 seconds (files took 0.16353 seconds to load)
-4 examples, 0 failures
+5 examples, 0 failures

Submission

There is no submission required for this assignment but the skills learned will be part of a follow-on assignment so please complete this to the requirements of the unit test.

diff --git a/Assignments/Lesson01-Assignment01-Case-Statement/README.md b/Assignments/Lesson01-Assignment01-Case-Statement/README.md index 7f72bf4..33cc262 100644 --- a/Assignments/Lesson01-Assignment01-Case-Statement/README.md +++ b/Assignments/Lesson01-Assignment01-Case-Statement/README.md @@ -89,18 +89,19 @@ solution. ```shell $ rspec -.FFF +.FFFF Failures: ... Finished in 0.02247 seconds (files took 0.1567 seconds to load) -4 examples, 3 failures +5 examples, 4 failures Failed examples: -rspec ./spec/case_spec.rb:17 # lesson1 check implementation remove if clause -rspec ./spec/case_spec.rb:21 # lesson1 check implementation remove elsif clause -rspec ./spec/case_spec.rb:25 # lesson1 check implementation missing case +rspec ./spec/lesson1_spec.rb:17 # lesson1 check implementation remove if clause +rspec ./spec/lesson1_spec.rb:21 # lesson1 check implementation remove elsif clause +rspec ./spec/lesson1_spec.rb:25 # lesson1 check implementation remove elsif clause +rspec ./spec/lesson1_spec.rb:29 # lesson1 check implementation missing case ``` 5. Implement the solution and re-test. @@ -127,7 +128,7 @@ as your solution. $ rspec Finished in 0.00304 seconds (files took 0.16353 seconds to load) -4 examples, 0 failures +5 examples, 0 failures ``` ### Submission From 0af17ef8da495c004ed1ead48616f4c6720a3f99 Mon Sep 17 00:00:00 2001 From: David Alexander Date: Wed, 28 Dec 2016 10:45:04 -0500 Subject: [PATCH 5/8] replaced duplicate elsif in lesson1_spec --- .../student-start/spec/lesson1_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assignments/Lesson01-Assignment01-Case-Statement/student-start/spec/lesson1_spec.rb b/Assignments/Lesson01-Assignment01-Case-Statement/student-start/spec/lesson1_spec.rb index b61525b..2a9ffc4 100644 --- a/Assignments/Lesson01-Assignment01-Case-Statement/student-start/spec/lesson1_spec.rb +++ b/Assignments/Lesson01-Assignment01-Case-Statement/student-start/spec/lesson1_spec.rb @@ -22,8 +22,8 @@ expect(srcCode).not_to include("elsif") end - it "remove elsif clause" do - expect(srcCode).not_to include("elsif") + it "missing else clause" do + expect(srcCode).not_to include("else") end it "missing case" do From c67ccb19f3d7fa2f5d58759bce2580b5057e917a Mon Sep 17 00:00:00 2001 From: David Alexander Date: Wed, 28 Dec 2016 10:56:12 -0500 Subject: [PATCH 6/8] changed not.to line 26 lesson1_spec --- .../student-start/module2_lesson1_formative.rb | 2 +- .../student-start/spec/lesson1_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Assignments/Lesson01-Assignment01-Case-Statement/student-start/module2_lesson1_formative.rb b/Assignments/Lesson01-Assignment01-Case-Statement/student-start/module2_lesson1_formative.rb index 25795f2..5e253c9 100644 --- a/Assignments/Lesson01-Assignment01-Case-Statement/student-start/module2_lesson1_formative.rb +++ b/Assignments/Lesson01-Assignment01-Case-Statement/student-start/module2_lesson1_formative.rb @@ -12,4 +12,4 @@ else puts "I guess nothing matched... But why?" -end \ No newline at end of file +end diff --git a/Assignments/Lesson01-Assignment01-Case-Statement/student-start/spec/lesson1_spec.rb b/Assignments/Lesson01-Assignment01-Case-Statement/student-start/spec/lesson1_spec.rb index 2a9ffc4..8ee3236 100644 --- a/Assignments/Lesson01-Assignment01-Case-Statement/student-start/spec/lesson1_spec.rb +++ b/Assignments/Lesson01-Assignment01-Case-Statement/student-start/spec/lesson1_spec.rb @@ -23,7 +23,7 @@ end it "missing else clause" do - expect(srcCode).not_to include("else") + expect(srcCode).to include("else") end it "missing case" do From 5caeba9fae10629e694b20cfe9af586cdcd1e94f Mon Sep 17 00:00:00 2001 From: David Alexander Date: Wed, 28 Dec 2016 10:58:09 -0500 Subject: [PATCH 7/8] Update lesson1_spec.rb --- .../student-start/spec/lesson1_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assignments/Lesson01-Assignment01-Case-Statement/student-start/spec/lesson1_spec.rb b/Assignments/Lesson01-Assignment01-Case-Statement/student-start/spec/lesson1_spec.rb index 8ee3236..772c601 100644 --- a/Assignments/Lesson01-Assignment01-Case-Statement/student-start/spec/lesson1_spec.rb +++ b/Assignments/Lesson01-Assignment01-Case-Statement/student-start/spec/lesson1_spec.rb @@ -22,7 +22,7 @@ expect(srcCode).not_to include("elsif") end - it "missing else clause" do + it "keep else clause" do expect(srcCode).to include("else") end From bca60ae40a092c89504d5ad3cc6721f5e9e9f6a3 Mon Sep 17 00:00:00 2001 From: Kalman Hazins Date: Sun, 14 Oct 2018 14:22:25 -0400 Subject: [PATCH 8/8] Update spec --- .../student-start/spec/lesson3_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Assignments/Lesson03-Assignment01-Classes/student-start/spec/lesson3_spec.rb b/Assignments/Lesson03-Assignment01-Classes/student-start/spec/lesson3_spec.rb index 9aa0484..8b3eaaf 100644 --- a/Assignments/Lesson03-Assignment01-Classes/student-start/spec/lesson3_spec.rb +++ b/Assignments/Lesson03-Assignment01-Classes/student-start/spec/lesson3_spec.rb @@ -4,6 +4,8 @@ describe "lesson3" do + subject { Person } + context "check results" do p1 = Person.new("Ivana", "Trump") p2 = Person.new("Eric", "Trump") @@ -29,7 +31,6 @@ end context "check class properties" do - subject(:class) { Person } it "missing search" do is_expected.to respond_to(:search)