Atalanta / cucumber-chef

Framework for test-driven infrastructure development
http://cucumber-chef.org
Apache License 2.0
265 stars 55 forks source link

When running tests, cucumber tries to load support/roles/file.rb and blows up #88

Closed anujbiyani closed 11 years ago

anujbiyani commented 11 years ago

The Wiki says to put roles in ./support/roles/ so I created ./support/roles/base.rb with the contents

name 'base'
description 'shared role applied to all nodes'

run_list(
  "recipe[chef-client]",
  "recipe[git]"
)

Now if I run any cucumber-chef test (regardless of whether or not the test tries to upload a role), I get the error

$> cucumber
  * cucumber-chef v2.0.7 - connected to test lab
undefined method `name' for main:Object (NoMethodError)
<chef_repo>/features/support/roles/base.rb:1:in `<top (required)>'
<gemset_dir>/gems/cucumber-1.2.1/lib/cucumber/rb_support/rb_language.rb:129:in `load'
<gemset_dir>/gems/cucumber-1.2.1/lib/cucumber/rb_support/rb_language.rb:129:in `load_code_file'
<gemset_dir>/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:172:in `load_file'
<gemset_dir>/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:84:in `block in load_files!'
<gemset_dir>/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:83:in `each'
<gemset_dir>/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:83:in `load_files!'
<gemset_dir>/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:175:in `load_step_definitions'
<gemset_dir>/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:40:in `run!'
<gemset_dir>/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:43:in `execute!'
<gemset_dir>/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:20:in `execute'
<gemset_dir>/gems/cucumber-1.2.1/bin/cucumber:14:in `<top (required)>'
<gemset_dir>/bin/cucumber:23:in `load'
<gemset_dir>/bin/cucumber:23:in `<main>'

It seems to be because Cucumber automatically loads files in ./features/support, then tries to execute base.rb which then blows up.

Without monkey-patching Cucumber, I'm not sure what to do about fixing this unless Cucumber-Chef is changed so it doesn't load roles from a subdirectory of ./features/support.

Another related concern I have is that any role that I create for my project is in ./roles, but any roles that the feature tests use have to be in ./features/support/roles. This implies that any role that I use in production and want to use in a test would have to be duplicated in both directories.

Is there any reason why Cucumber-Chef shouldn't load roles from ./roles?

(For now I'm simply uploading roles by hand with cc-knife role from file FILE.)

zpatten commented 11 years ago

Ya this shouldn't be happening; I should have something for you in the next day or so.

zpatten commented 11 years ago

Sorry; holidays took most of my time so I wasn't able to work on this issue. Going to take a stab at it this weekend.

anujbiyani commented 11 years ago

No problem, I'm quite happy so far with manually uploading roles since that's the same thing I have to do in production.

zpatten commented 11 years ago

Been working on CC; I think I know why your having issues. You need at add something along the lines of this to your cucumber.yml in the root of your chef-repo:

    ---
    default: -c -v --exclude support/cookbooks --exclude support/data_bags --exclude support/keys --exclude support/roles

Otherwise; cucumber tries to load all files under the features directory and since cucumber doesn't rightfully understand the Chef DSL it will proceed to blow up.

zpatten commented 11 years ago

Also; if you want to load roles directory from your repo; you should be able to. Instead of using ./features/support/roles/xyz, you should be able to just say ./roles/xyz.

anujbiyani commented 11 years ago

The cucumber.yml addition worked perfectly, thanks!

I thought I had tried uploading from ./roles/xyz and found that it wasn't working, but I just tried it and it's working just fine. I must've screwed something up a while back or be misremembering.

I'll update the Wiki with the cucumber.yml info; I'm fairly new to Cucumber and so didn't know about that file, and I think it'd help people like me if this info were stated (or maybe just this issue linked to) from the Wiki.

Thanks again.

zpatten commented 11 years ago

Awesome; glad to hear that worked for you. I must admit the wiki needs some loving; thank you for adding the note to it, I appreciate it very much!