Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lackluster type coercion #445

Closed
conorsch opened this issue Feb 9, 2016 · 2 comments
Closed

Lackluster type coercion #445

conorsch opened this issue Feb 9, 2016 · 2 comments
Labels
Aspect: Docs Write the Fine Manual Type: Enhancement Improves an existing feature
Milestone

Comments

@conorsch
Copy link

conorsch commented Feb 9, 2016

As of v0.10.1, the following inspec test fails:

describe port('5555') do
  it { should be_listening }
end

with the traceback:

  1) Port  5555 should be listening
     Failure/Error: DEFAULT_FAILURE_NOTIFIER = lambda { |failure, _opts| raise failure }
       expected `Port  5555.listening?` to return true, got false
     # ./test/integration/default/riemann_server_spec.rb:63:in `block (2 levels) in load'
     # /home/conor/.gem/ruby/2.1.0/gems/inspec-0.10.1/lib/inspec/runner_rspec.rb:55:in `run'
     # /home/conor/.gem/ruby/2.1.0/gems/kitchen-inspec-0.11.0/lib/kitchen/verifier/inspec.rb:43:in `call'
     # /home/conor/.gem/ruby/2.1.0/gems/test-kitchen-1.5.0/lib/kitchen/instance.rb:405:in `block in verify_action'
     # /home/conor/.gem/ruby/2.1.0/gems/test-kitchen-1.5.0/lib/kitchen/instance.rb:495:in `call'
     # /home/conor/.gem/ruby/2.1.0/gems/test-kitchen-1.5.0/lib/kitchen/instance.rb:495:in `synchronize_or_call'
     # /home/conor/.gem/ruby/2.1.0/gems/test-kitchen-1.5.0/lib/kitchen/instance.rb:460:in `block in action'
     # /home/conor/.gem/ruby/2.1.0/gems/test-kitchen-1.5.0/lib/kitchen/instance.rb:459:in `action'
     # /home/conor/.gem/ruby/2.1.0/gems/test-kitchen-1.5.0/lib/kitchen/instance.rb:401:in `verify_action'
     # /home/conor/.gem/ruby/2.1.0/gems/test-kitchen-1.5.0/lib/kitchen/instance.rb:348:in `block in transition_to'
     # /home/conor/.gem/ruby/2.1.0/gems/test-kitchen-1.5.0/lib/kitchen/instance.rb:347:in `each'
     # /home/conor/.gem/ruby/2.1.0/gems/test-kitchen-1.5.0/lib/kitchen/instance.rb:347:in `transition_to'
     # /home/conor/.gem/ruby/2.1.0/gems/test-kitchen-1.5.0/lib/kitchen/instance.rb:160:in `verify'
     # /home/conor/.gem/ruby/2.1.0/gems/test-kitchen-1.5.0/lib/kitchen/command.rb:176:in `public_send'
     # /home/conor/.gem/ruby/2.1.0/gems/test-kitchen-1.5.0/lib/kitchen/command.rb:176:in `block (2 levels) in run_action'

However, this inspec test passes just fine:

describe port(5555) do
  it { should be_listening }
end

The only difference is whether a string or an int was passed to the function. Surely the library can learn to accommodate inputs of both types and treat them accordingly. Admittedly, the port docs do provide examples with ints, rather than strings, but overall this is the type of decision a machine can make fine, and it will doubtless frustrate first-time users of the project.

Assuming updating the code would be problematic, because it'd be hard to use numeric comparison operators, at least some documentation about the importance of types would be helpful.

@arlimus
Copy link
Contributor

arlimus commented Feb 9, 2016

+1 :)

this looks like a theme that'll come up more often; we have recently introduced a fantastic helper at the other end of the equation: #318 . So this issue covers input, which the resource would have to consider itself; but if we create something that other people can use, including we can use on our resources, to make these cases easier, that'd be helpful.

there's also the other view, which could warn you about using integers instead of strings. Like a linter for these cases.

Let's check which is more user-friendly and less confusing in the end.

@chris-rock chris-rock added Type: Enhancement Improves an existing feature Aspect: Docs Write the Fine Manual labels Mar 3, 2016
@chris-rock chris-rock added this to the 1.0.0 milestone Jul 26, 2016
@chris-rock chris-rock modified the milestones: 1.0.0, 1.1.0 Sep 21, 2016
@arlimus
Copy link
Contributor

arlimus commented Apr 26, 2017

Now works as intended. Tested in InSpec v1.21

@arlimus arlimus closed this as completed Apr 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Aspect: Docs Write the Fine Manual Type: Enhancement Improves an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants