2017-02-16 2 views
2

環境rp_envのために解析できませんでした、と私は試し書きを始めています:RSpecの:私はRSpecの-人形に新しいです

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' 
    } 

これは「テストのテスト」のほうが多いですが、物事は失敗し続けます。 私は取得しています:

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)>' 

ライン39はis_expected.to contain_class( 'rcjenkins :: nginxの')です。誰でも何が起こっているのか知っていますか?

編集: 私も気付いた、私はテストを変更する、私に同じエラーを与えることに気づいた。私は何が足りないのですか? rp_envとは何ですか?

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

:変数ルビーfacts{ :osfamily => 'RedHat' }であるが、これは、このようにマニフェスト人形を生成した場合

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

+0

Dominic Clealがあなたの 'let(:pre_condition)'を思いついたという問題の他に、エラーメッセージの間違った部分にも焦点を当てています。エラーメッセージに 'localhost.localdomainノードの行1時11分に構文エラー'があります。投稿していないコードのどこかに構文エラーがあります。それはあなたの直ちの問題を解決します。 –

+0

さて、rspec-puppetは与えられたパラメータでクラス宣言に結合された 'pre_condition'を含むマニフェストを生成します。パペットはエラーのマニフェストパスが指定されていないので、エラーは別のファイルではなくマニフェストを生成したものです。おそらく 'pre_condition'構文です。 –

+0

@DominicClealそれで、それはシンボルハッシュキーを定義しているマニフェストの部分で失敗します。意味をなさないこの質問がどのように進化するか見るために行くつもりですが、あなたがそれを釘付けにしているように見えるので、あなたの理論を割り引かない限りすぐにupvoteします。 –

答えて

0

OPも約rp_envと尋ねました。

環境rp_envは、 "Rspec-Puppet Environment"の略で、Rspec-puppet自身が追加した環境の偽の値です。

コードでhereと定義されています。

Rspec-puppetコードで環境を自分で設定する場合は、便利な投稿hereがあります。

2

削除するか、それが有効な人形マニフェストを生成していない、あなたのpre_conditionを修正osfamilyハッシュキーの前にあるコロンは、パペットマニフェストでは無効です(文字列でなければなりません(例:'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

ええ、私はその問題を再現することができず、1年以上rspec-puppetでサポートされています。質問を編集して 'pre_condition'を削除するときに、エラー(構文エラーの原因)に関する詳細を表示することができれば、さらに助けてくれるかもしれません。 –

関連する問題