Class: Test::Unit::TestCase
- Inherits:
-
Object
- Object
- Test::Unit::TestCase
show all
- Defined in:
- lib/unfuzzle/test/test_helper.rb,
lib/graft/test/test_helper.rb
Direct Known Subclasses
Graft::Json::AttributeTest, Graft::Xml::AttributeTest, Graft::Xml::BooleanTest, Graft::Xml::DateTest, Graft::Xml::IntegerTest, Graft::Xml::StringTest, Graft::Xml::TimeTest, HashTest, JsonModelTest, Unfuzzle::ComponentTest, Unfuzzle::MilestoneTest, Unfuzzle::PriorityTest, Unfuzzle::ProjectTest, Unfuzzle::RequestTest, Unfuzzle::ResponseTest, Unfuzzle::SeverityTest, Unfuzzle::TicketTest, UnfuzzleTest, XmlModelTest
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.implementation_klass ⇒ Object
12
13
14
15
16
17
|
# File 'lib/graft/test/test_helper.rb', line 12
def self.implementation_klass
class_name = self.to_s.match(/([a-zA-Z]+)Test$/)[1]
klass = Graft::Xml::Type.const_get(class_name)
klass
end
|
.read_fixture(method_name) ⇒ Object
12
13
14
15
|
# File 'lib/unfuzzle/test/test_helper.rb', line 12
def self.read_fixture(method_name)
file = File.dirname(__FILE__) + "/fixtures/#{method_name}.xml"
File.read(file)
end
|
.should_convert(source, options) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/graft/test/test_helper.rb', line 19
def self.should_convert(source, options)
klass = self.implementation_klass
target = options[:to]
should "be able to convert '#{source}' to #{target}" do
o = klass.new(source)
o.value.should == target
end
end
|
.should_fail_when_converting(source) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/graft/test/test_helper.rb', line 29
def self.should_fail_when_converting(source)
klass = self.implementation_klass
should "fail when converting '#{source}'" do
o = klass.new(source)
lambda { o.value }.should raise_error(Graft::Xml::Type::ConversionError)
end
end
|
.should_set_a_value_for(attribute, value = nil) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/unfuzzle/test/test_helper.rb', line 47
def self.should_set_a_value_for(attribute, value = nil)
class_name = self.to_s.sub(/^Unfuzzle::(.*)Test$/, '\\1')
klass = Unfuzzle.const_get(class_name)
value = attribute if value.nil?
should "be able to set a value for :#{attribute}" do
object = klass.new
object.send("#{attribute}=", value)
object.send(attribute).should == value
end
end
|
.value_for(method_name, options) ⇒ Object
41
42
43
44
45
|
# File 'lib/unfuzzle/test/test_helper.rb', line 41
def self.value_for(method_name, options)
should "have a value for :#{method_name}" do
@object.send(method_name).should == options[:is]
end
end
|
.when_populating(klass, options, &block) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/unfuzzle/test/test_helper.rb', line 33
def self.when_populating(klass, options, &block)
context "with data populated for #{klass}" do
setup { @object = klass.new(read_fixture(options[:from])) }
merge_block(&block)
end
end
|
Instance Method Details
#mock_request_cycle(options) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/unfuzzle/test/test_helper.rb', line 21
def mock_request_cycle(options)
response = Unfuzzle::Response.new(stub())
data = read_fixture(options[:data])
response.stubs(:body).with().returns(data)
Unfuzzle::Request.stubs(:get).with(options[:for]).returns(response)
response
end
|
#read_fixture(method_name) ⇒ Object
17
18
19
|
# File 'lib/unfuzzle/test/test_helper.rb', line 17
def read_fixture(method_name)
self.class.read_fixture(method_name)
end
|