Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
wrap specs in class; introduce 'let' block
Browse files Browse the repository at this point in the history
After watching a video on Boston Ruby, it is better to wrap your files
in a class, so I've done that.  Nothing else changed in that instance.

Also, minitest 2.6.0 introduced the let syntax to mimic a behavior in RSpec,
so I made a change for @session to be a let :session block instead.  Not sure
about performance on it, but if I can get mocking to work with these tests, it
might not matter.
  • Loading branch information
Nick Klauer (a03182) committed Sep 15, 2011
1 parent bfd370c commit 55c8a36
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 137 deletions.
183 changes: 94 additions & 89 deletions spec/config_spec.rb
@@ -1,103 +1,108 @@
require_relative 'spec_helper'

class ConfigTests < MiniTest::Unit::TestCase

describe Mantis::Config do
describe Mantis::Config do

before do
@session = create_session
@configs = %w{ statuses priorities severities reproducibilities
let :session do
create_session
end

before do
@configs = %w{ statuses priorities severities reproducibilities
projections etas resolutions access_levels
project_statuses project_view_states view_states
custom_field_types }
end

describe " config" do
it "should retrieve statuses, priorities, severities, and more" do
@configs.each { |w|
@session.config.send(w).size.must_be :>=, 1
}
end

describe " config" do
it "should retrieve statuses, priorities, severities, and more" do
@configs.each { |w|
session.config.send(w).size.must_be :>=, 1
}
end
it "should return an array for all config types" do
@configs.each { |c|
assert_instance_of Array, @session.config.send(c)
}
@configs.each { |c|
assert_instance_of Array, session.config.send(c)
}
end
it "should get the statuses of Mantis we're connecting to" do
wont_be_nil_for(@session.config.statuses, "acknowledged")
end
it "should get the priorities of Mantis we're connecting to" do
wont_be_nil_for(@session.config.priorities, "none")
end
it "should get the severities of Mantis we're connecting to" do
wont_be_nil_for(@session.config.severities, "feature")
end
it "should get the reproducibilities of Mantis we're connecting to" do
wont_be_nil_for(@session.config.reproducibilities, "always")
end
it "should get the version of Mantis we're connecting to" do
@session.config.version.wont_be_nil
end
it "should get the projections of Mantis we're connecting to" do
wont_be_nil_for(@session.config.projections, "none")
end
it "should get the ETA's of Mantis we're connecting to" do
wont_be_nil_for(@session.config.etas, "none")
end
it "should get the resolutions of Mantis we're connecting to" do
wont_be_nil_for(@session.config.resolutions, "open")
end
it "should get the access levels of Mantis we're connecting to" do
wont_be_nil_for(@session.config.access_levels, "viewer")
end
it "should get the project statuses of Mantis we're connecting to" do
wont_be_nil_for(@session.config.project_statuses, "development")
end
it "should get the project view states of Mantis we're connecting to" do
wont_be_nil_for(@session.config.project_view_states, "public")
end
it "should get the issue view states of Mantis we're connecting to" do
wont_be_nil_for(@session.config.view_states, "public")
end
it "should get the custom_field_types of Mantis we're connecting to" do
wont_be_nil_for(@session.config.custom_field_types, "Numeric")
end
it "project_status_for should convert :symbol to \"string\"" do
@session.config.object_ref_for_value(:project_status, :development).wont_be_empty
end
it "view_state_for should convert :symbol to \"string\"" do
@session.config.object_ref_for_value(:view_state, :public).wont_be_empty
end
it "access_min should convert :symbol to \"string\"" do
@session.config.object_ref_for_value(:access_min, :viewer).wont_be_empty
end

describe "statuses" do
it "should map acknowledged status" do
s = @session.config.object_ref_for_value(:project_status, :release)
assert s[:name] == "release"
it "should get the statuses of Mantis we're connecting to" do
wont_be_nil_for(session.config.statuses, "acknowledged")
end
it "should get the priorities of Mantis we're connecting to" do
wont_be_nil_for(session.config.priorities, "none")
end
it "should get the severities of Mantis we're connecting to" do
wont_be_nil_for(session.config.severities, "feature")
end
it "should get the reproducibilities of Mantis we're connecting to" do
wont_be_nil_for(session.config.reproducibilities, "always")
end
it "should get the version of Mantis we're connecting to" do
session.config.version.wont_be_nil
end
it "should get the projections of Mantis we're connecting to" do
wont_be_nil_for(session.config.projections, "none")
end
it "should get the ETA's of Mantis we're connecting to" do
wont_be_nil_for(session.config.etas, "none")
end
it "should get the resolutions of Mantis we're connecting to" do
wont_be_nil_for(session.config.resolutions, "open")
end
it "should get the access levels of Mantis we're connecting to" do
wont_be_nil_for(session.config.access_levels, "viewer")
end
it "should get the project statuses of Mantis we're connecting to" do
wont_be_nil_for(session.config.project_statuses, "development")
end
it "should get the project view states of Mantis we're connecting to" do
wont_be_nil_for(session.config.project_view_states, "public")
end
it "should get the issue view states of Mantis we're connecting to" do
wont_be_nil_for(session.config.view_states, "public")
end
it "should get the custom_field_types of Mantis we're connecting to" do
wont_be_nil_for(session.config.custom_field_types, "Numeric")
end
it "project_status_for should convert :symbol to \"string\"" do
session.config.object_ref_for_value(:project_status, :development).wont_be_empty
end
it "view_state_for should convert :symbol to \"string\"" do
session.config.object_ref_for_value(:view_state, :public).wont_be_empty
end
it "access_min should convert :symbol to \"string\"" do
session.config.object_ref_for_value(:access_min, :viewer).wont_be_empty
end
end # statuses

describe "meta-method mapping" do
meth_to_val = { status: :acknowledged,
priority: :none,
severity: :feature,
reproducibility: :always,
projection: :none,
eta: :none,
resolution: :open,
access_level: :viewer,
project_status: :development,
project_view_state: :public,
view_state: :public,
custom_field_type: :Numeric
}
meth_to_val.each { |k,v|
it "should find a list of ObjectRef Type for #{k}" do
refute_nil @session.config.object_ref_for_value(k,v)
describe "statuses" do
it "should map acknowledged status" do
s = session.config.object_ref_for_value(:project_status, :release)
assert s[:name] == "release"
end
}
end # statuses

describe "meta-method mapping" do
meth_to_val = { status: :acknowledged,
priority: :none,
severity: :feature,
reproducibility: :always,
projection: :none,
eta: :none,
resolution: :open,
access_level: :viewer,
project_status: :development,
project_view_state: :public,
view_state: :public,
custom_field_type: :Numeric
}
meth_to_val.each { |k,v|
it "should find a list of ObjectRef Type for #{k}" do
refute_nil session.config.object_ref_for_value(k,v)
end
}

end # meta-method mapping
end # config
end # Mantis::Config
end # meta-method mapping
end # config
end # Mantis::Config
end # ConfigTest
11 changes: 6 additions & 5 deletions spec/filters_spec.rb
@@ -1,16 +1,16 @@
require_relative 'spec_helper'

class FiltersTest < MiniTest::Unit::TestCase
describe Mantis::Filters do

before do
@session = create_session
let :session do
create_session
end

describe "listing filters" do
it "should list filters for a user" do
skip
prjs = @session.projects.list
filters = @session.filters.list(prjs[0].id)
prjs = session.projects.list
filters = session.filters.list(prjs[0].id)
assert_instance_of Array, filters.class
if filters.size > 0
assert_instance_of FilterData, filters[0]
Expand All @@ -30,3 +30,4 @@
end
end # issues in filter
end # Mantis::Filters
end # FiltersTest
30 changes: 18 additions & 12 deletions spec/issues_spec.rb
@@ -1,20 +1,25 @@
require_relative 'spec_helper'

class IssuesTests < MiniTest::Unit::TestCase

describe Mantis::Issues do

let :session do
create_session
end

before do
@projects = []
@issues_list = []
@session = create_session
@project_id = @session.projects.create params={
@project_id = session.projects.create params={
name: random_alphanumeric }
@projects << @project_id
@project = @session.projects.find_by_id(@project_id)
@project = session.projects.find_by_id(@project_id)
end

describe "creating issues" do
it "should create a simple issue given a project" do
id = @session.issues.add params={
id = session.issues.add params={
project: 45,
summary: "Some Summary Description",
description: "More Detailed Response will go here",
Expand All @@ -33,37 +38,38 @@

describe "deleting issues" do
it "should delete an issue with an id" do
id = @session.issues.add params={
id = session.issues.add params={
project: 45, # test has been defined by it for now, should refactor it out
summary: random_alphanumeric,
description: random_alphanumeric(256),
category: "General"
}
@session.issues.delete?(id).must_equal true
session.issues.delete?(id).must_equal true
end
end # deleting issues

describe "listing issues" do
it "should retrieve an issue by id" do
@issue = @session.issues.by_id 1
@issue = session.issues.by_id 1
wont_be_nil @issue
end

it "should retrieve issue componetns by issue[:parameter] lookup" do
@issue = @session.issues.by_id 1
@issue = session.issues.by_id 1
@issue[:id].to_i.must_be_same_as 1
end

it "should retrieve issue components by dot.method invocation" do
@issue = @session.issues.by_id 1
@issue = session.issues.by_id 1
@issue.id.to_i.must_be_same_as 1
end
end # listing issues

after do
#clear_issues @project_id
#clear_projects @session
remove_given_projects(@session, @projects) if @projects # should be empty anyway
remove_given_issues(@session, @issues_list) if @issues_list
#clear_projects session
remove_given_projects(session, @projects) if @projects # should be empty anyway
remove_given_issues(session, @issues_list) if @issues_list
end
end # Mantis::Issues
end # IssuesTests
9 changes: 5 additions & 4 deletions spec/mantisrb_spec.rb
@@ -1,15 +1,16 @@
require_relative 'spec_helper'

class SessionTests < MiniTest::Unit::TestCase
describe Mantis::Session do

before do
@session = create_session
let :session do
create_session
end

describe "Mantis" do

it "should strip all :\"@xsi:type\" elements" do
@session.config.statuses.each { |t| t.keys.wont_include "@xsi:type".to_sym }
session.config.statuses.each { |t| t.keys.wont_include "@xsi:type".to_sym }
end

it "should convert single result Array of Arrays to Hash" do
Expand All @@ -18,4 +19,4 @@

end # Mantis
end # Mantis::Session

end # SessionTests

0 comments on commit 55c8a36

Please sign in to comment.