A
Adam Akhtar
Hi im still learning testing and bit confused about testing the
parse_file method below
class Data
def initialize a_file
@records = parse_file(a_file)
end
def parse_file(a_file)
....
end
end
To test parse_file i must first create a new data object i.e.
sample_data = Data.new("survey")
then in my test
assert_equal blah, sample_data.parse_file("sample.txt")
but in the test when i create a new data object the the method will be
invoked via initialize before ive even tested it which doesnt sit right
with me.
Should i be mocking this? Or is there a simpler solution to this.
parse_file method below
class Data
def initialize a_file
@records = parse_file(a_file)
end
def parse_file(a_file)
....
end
end
To test parse_file i must first create a new data object i.e.
sample_data = Data.new("survey")
then in my test
assert_equal blah, sample_data.parse_file("sample.txt")
but in the test when i create a new data object the the method will be
invoked via initialize before ive even tested it which doesnt sit right
with me.
Should i be mocking this? Or is there a simpler solution to this.