spriteCloud / lapis-lazuli

Cucumber helper functions and scaffolding for easier test automation suite development.
Other
7 stars 7 forks source link

No error is thrown when the config file doesnt find the variable #31

Closed barzilay closed 8 years ago

barzilay commented 8 years ago

Actual

Using _env('configvariable') doesnt give an error if it doesnt find the env and returns an empty value

Expected

sjieg commented 8 years ago

./LL/world/config.rb:391

return value

./LL/world/config.rb:318

value = default

./LL/world/config.rb:312

def var_from_env(var, default=nil)

So, because the default for default is nil, the method will return nil if it failed.

To override this we can simply add a error('...') if value === nil before returning the value. First we should check what the impact of this change will be.

osteenbergen commented 8 years ago

env function should use the same structure as the config function. We need to know if the default was used and set to nil or not.

def env(variable=false, default=(no_default_set=true;nil))

Now you can easily change the return from

return self.config("#{@env}.#{variable}",default)

to

result = self.config("#{@env}.#{variable}",default)

if no_default_set == true and result.nil?
    raise "Unknown environment variable '#{variable}' and no default given!"
end

return result