Implement Recipe#filepath method:
Returns the filepath of the recipe when it is built from a file.
This commit is contained in:
parent
0ac6217245
commit
37e17d1030
@ -1,14 +1,15 @@
|
|||||||
module Producer
|
module Producer
|
||||||
module Core
|
module Core
|
||||||
class Recipe
|
class Recipe
|
||||||
attr_reader :code
|
attr_reader :code, :filepath
|
||||||
|
|
||||||
def self.from_file(filepath)
|
def self.from_file(filepath)
|
||||||
new(File.read(filepath))
|
new(File.read(filepath), filepath)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(code)
|
def initialize(code, filepath = nil)
|
||||||
@code = code
|
@code = code
|
||||||
|
@filepath = filepath
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate
|
def evaluate
|
||||||
|
@ -8,11 +8,16 @@ module Producer::Core
|
|||||||
subject(:recipe) { Recipe.new(code) }
|
subject(:recipe) { Recipe.new(code) }
|
||||||
|
|
||||||
describe '.from_file' do
|
describe '.from_file' do
|
||||||
|
let (:filepath) { fixture_path_for 'recipes/empty.rb' }
|
||||||
|
subject(:recipe) { Recipe.from_file(filepath) }
|
||||||
|
|
||||||
it 'builds a recipe whose code is read from given file path' do
|
it 'builds a recipe whose code is read from given file path' do
|
||||||
filepath = fixture_path_for 'recipes/empty.rb'
|
|
||||||
recipe = Recipe.from_file(filepath)
|
|
||||||
expect(recipe.code).to eq File.read(filepath)
|
expect(recipe.code).to eq File.read(filepath)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'builds a recipe whose file path is set from given file path' do
|
||||||
|
expect(recipe.filepath).to eq filepath
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#initialize' do
|
describe '#initialize' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user