2017-02-16 37 views
2

我是新來的rspec的傀儡,我有試寫開頭:Rspec的:無法解析的環境rp_env

我寫了這個代碼:

describe 'rcjenkins' do 
    let(:facts) do 
    { 
     :osfamily => 'RedHat' 
    } 
    end 
    let(:pre_condition) do 
    "$facts = #{facts}" 
    end 

    let(:params) do 
    { 
     :host => "127.0.0.1", 
     :github_token => "valor", 

    } 
    end 
    it do 
    is_expected.to contain_class('rcjenkins::nginx') 
    end 
end 

這應該測試:

class rcjenkins($host, $github_token) { 
    include rcjenkins::package 

    class { 'nginx': } 

    nginx::resource::upstream { 'jenkins': 
    members => [ 
     'localhost:8080' 
    ] 
    } 

    nginx::resource::vhost { $host: 
    proxy => 'http://jenkins' 
    } 

    nginx::resource::location { 'jenkins_root': 
    ensure   => present, 
    vhost   => $host, 
    location  => '/status', 
    location_alias => '/usr/share/nginx/html' 
    } 

這更多的是「測試測試」,但事情依然失敗。 我得到:39

1) rcjenkins Treco should contain Class[rcjenkins::nginx] 
    Failure/Error: is_expected.to contain_class('rcjenkins::nginx') 

    Puppet::ParseErrorWithIssue: 
     Could not parse for environment rp_env: Syntax error at ':' at line 1:11 on node localhost.localdomain 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/parser_support.rb:127:in `on_error' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/lexer2.rb:712:in `scan' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/parser_support.rb:240:in `_parse' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/parser_support.rb:134:in `parse_string' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/pops/parser/evaluating_parser.rb:28:in `parse_string' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/e4_parser_adapter.rb:29:in `parse' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/node/environment.rb:507:in `perform_initial_import' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/node/environment.rb:247:in `known_resource_types' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:767:in `block in initvars' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/context.rb:65:in `override' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet.rb:293:in `override' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:765:in `initvars' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:422:in `initialize' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:33:in `new' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/parser/compiler.rb:33:in `compile' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/catalog/compiler.rb:266:in `block (2 levels) in compile' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/util/profiler/around_profiler.rb:58:in `profile' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/util/profiler.rb:51:in `profile' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/catalog/compiler.rb:264:in `block in compile' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/util.rb:223:in `block in benchmark' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/util.rb:222:in `benchmark' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/catalog/compiler.rb:262:in `compile' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/catalog/compiler.rb:53:in `find' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/puppet-4.9.2/lib/puppet/indirector/indirection.rb:194:in `find' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/adapters.rb:74:in `catalog' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/adapters.rb:148:in `catalog' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:203:in `build_catalog_without_cache' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:212:in `block in build_catalog' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/cache.rb:17:in `call'is_expected.to contain_class('rcjenkins::nginx') 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/cache.rb:17:in `get' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:211:in `build_catalog' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:30:in `block in load_catalogue' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:178:in `with_vardir' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:19:in `load_catalogue' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/example/class_example_group.rb:7:in `catalogue' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/support.rb:11:in `block in subject' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/matchers/create_generic.rb:82:in `call' 
    # /home/luis.brandao/.rvm/gems/ruby-2.2.6/gems/rspec-puppet-2.5.0/lib/rspec-puppet/matchers/create_generic.rb:82:in `matches?' 
    # ./spec/classes/rcjenkins_spec.rb:39:in `block (3 levels) in <top (required)>' 

線是is_expected.to contain_class( 'rcjenkins :: nginx的')。任何人都知道發生了什麼?

編輯: 我也注意到,無論我改變測試,給我同樣的錯誤。我錯過了什麼?什麼是rp_env?

+0

除了Dominic Cleal用你的'let(:pre_condition)'帶來的問題之外,你還關注錯誤信息的錯誤部分。該錯誤消息說'節點localhost.localdomain'上的線路1:11處的'Syntax error at':'。在您未發佈的代碼中,您有其他語法錯誤。這將解決你的直接問題。 –

+0

那麼,rspec-puppet會生成一個包含'pre_condition'的清單,並使用給定的參數與一個類聲明結合在一起。錯誤來自生成的清單而不是另一個文件,因爲Puppet沒有給出錯誤的清單路徑。這可能是'pre_condition'語法。 –

+0

@DominicCleal因此,它將在清單中定義符號散列鍵的部分失敗。說得通。去看看這個問題是如何演變的,但它似乎就像你釘住了它,所以很快就會投入運行,除非他打折了你的理論。 –

回答

0

該OP還詢問了關於rp_env

環境rp_env代表「Rspec-Puppet Environment」,是Rspec-puppet本身添加的環境的假價值。

它在代碼中定義爲here

如果您希望自己在您的Rspec-puppet代碼中設置環境,則有一個有用的帖子here,它解釋瞭如何執行此操作。

2

刪除或修復您的pre_condition,它不產生有效的木偶清單:

let(:pre_condition) do 
    "$facts = #{facts}" 
end 

如果Ruby的變量facts{ :osfamily => 'RedHat' }然後這會產生一個木偶表現是這樣的:

$facts = {:osfamily=>'RedHat'} 

osfamily散列鍵前的冒號在Puppet清單中無效(它必須是字符串,例如'osfamily')。

我不認爲有什麼理由在這裏設置pre_condition,您的let(:facts)應該是足夠的。

+0

沒有這個先決條件,我不斷收到「評估錯誤:運營商'[]'不適用於Undef值」 ref:https://github.com/rodjek/rspec-puppet/issues/344 – Techmago

+0

@Techmago該問題是絕對的謊言。我在RSpec Puppet中一直使用'let(:facts){{fact:'fact_value'}}'並且它填充'$ facts'哈希值。你和他在這裏有其他問題。 –

+0

是的,我不能再現這個問題,並且在rspec-puppet中已經支持了一年多。如果通過編輯問題來刪除'pre_condition'時,可以顯示有關錯誤的更多細節(語法錯誤的來源),我們可能會進一步提供幫助。 –

相關問題