Skip to content

Commit

Permalink
#98 More rspec test examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Bue Petersen committed May 1, 2017
1 parent 898cedd commit 189c1ae
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 18 deletions.
38 changes: 38 additions & 0 deletions spec/pactask_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require_relative '../lib/model.rb'

RSpec.describe Model do
describe "class PACTask" do

describe ".new" do
context "Task initialized" do
let(:pt) { Model::PACTask.new() }
it "without task id should have task_id nil" do
expect(pt.task_id).to eq(nil)
end

let(:pt_id) { Model::PACTask.new(3) }
it "with something else than a string should raiseArgument error as we expect it to be a string later" do
expect{Model::PACTask.new(3)}.to raise_error(ArgumentError)
end
end
end



describe "applies_to" do
let(:pt) { Model::PACTask.new() }

context "Given a new task" do
it "applies_to should be empty" do
expect(pt.applies_to.length).to be 0
end

it "applies_to should return the set of applied tasks systems" do
pt.applies_to = 'mytaskssystem'
ts = Set.new ['mytaskssystem']
expect(pt.applies_to).to eq(ts) # not object identity, just content
end
end
end
end
end
27 changes: 13 additions & 14 deletions spec/task_spec.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
require_relative '../lib/model.rb'

RSpec.describe Model do
describe "class PACTask" do
describe "class PACTask" do
describe "method: new" do
context "When a PACTask is created" do
it "the data object should not be there" do
ta = Model::PACTask.new(1)
ta = Model::PACTask.new("1")
expect(ta.data).to be_nil
end
end
end
end
describe "applies_to" do
let(:ta) { Model::PACTask.new(2) }
let(:ta_full) {
m = Model::PACTask.new(2)
let(:ta) { Model::PACTask.new("2") }
let(:ta_full) {
m = Model::PACTask.new("2")
m.applies_to = 'jira'
m
}

context "Given a new task" do
it "applies_to should be empty" do
expect(ta.applies_to.length).to be 0
expect(ta.applies_to.length).to be 0
end

it "should append the applied string when called" do
Expand All @@ -37,7 +37,7 @@
end

describe "add_label" do
let(:std_task) { Model::PACTask.new(1) }
let(:std_task) { Model::PACTask.new("1") }
context "Given a new task" do
it "label should be empty" do
expect(std_task.label.length).to be 0
Expand All @@ -46,16 +46,15 @@

context "When the user adds a label to the task" do
it "the label should be added to the list" do
end
end
end
end
end
end
describe "class: PACTaskCollection" do
context "Given a new collection" do
it "HAHA" do
expect(1).to be 1
it "HAHA" do
expect(1).to be 1
end
end
end
end
end

8 changes: 4 additions & 4 deletions test/unit/modeltest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def test_PACTask_initialize

# Applies to method is setting the tasks systems the PAC tasks have data in
def test_PACtask_applies_to_method
tc = Model::PACTask.new()
ts = Model::PACTask.new()


assert_equal(Set.new,tc.applies_to(),"Applies to is default empty set.")
assert_equal(Set.new,ts.applies_to(),"Applies to is default empty set.")
# Applies to take a string matching the entry for task system in the config file
tc.applies_to='mytasksystem'
ts.applies_to='mytasksystem'
tasksystem = Set.new ['mytasksystem']
assert_equal(tasksystem,tc.applies_to(),"Applies to tasks system not 'mytasksystem' as expected.")
assert_equal(tasksystem,ts.applies_to(),"Applies to tasks system not 'mytasksystem' as expected.")
end

def test_model_task_collection
Expand Down

0 comments on commit 189c1ae

Please sign in to comment.