Skip to content
This repository has been archived by the owner on Dec 27, 2019. It is now read-only.

Treat arrays like arrays, not strings #15

Open
RyanFrantz opened this issue Sep 28, 2017 · 1 comment
Open

Treat arrays like arrays, not strings #15

RyanFrantz opened this issue Sep 28, 2017 · 1 comment
Labels

Comments

@RyanFrantz
Copy link
Contributor

RyanFrantz commented Sep 28, 2017

When writing tests where a parameter is an array, we end up writing out a string version of the array. This breaks tests like package. Here are some example failures related to this issue:

Arrays should be treated like arrays, not strings:

  9) blp-chef-workstation::_os installs package "mysql-connector-python"
     Failure/Error: expect(chef_run).to install_package('mysql-connector-python').with(package_name: '["mysql-connector-python"]')

       expected "yum_package[mysql-connector-python]" to have parameters:

         package_name "[\"mysql-connector-python\"]", was ["mysql-connector-python"]
     # ./spec/umami/unit/recipes/_os_spec.rb:39:in `block (2 levels) in <top (required)>'

  10) blp-chef-workstation::_os installs package "ksh, lsof, procps, psmisc, strace, sysstat, tcpdump, telnet, unzip, zsh"
      Failure/Error: expect(chef_run).to install_package('ksh, lsof, procps, psmisc, strace, sysstat, tcpdump, telnet, unzip, zsh').with(package_name: '["ksh", "lsof", "procps", "psmisc", "strace", "sysstat", "tcpdump", "telnet", "unzip", "zsh"]')

        expected "yum_package[ksh, lsof, procps, psmisc, strace, sysstat, tcpdump, telnet, unzip, zsh]" to have parameters:

          package_name "[\"ksh\", \"lsof\", \"procps\", \"psmisc\", \"strace\", \"sysstat\", \"tcpdump\", \"telnet\", \"unzip\", \"zsh\"]", was ["ksh", "lsof", "procps", "psmisc", "strace", "sysstat", "tcpdump", "telnet", "unzip", "zsh”]

The likely behavior we want is that if we encounter an array (say, of packages), we write a looping test, like so:

%w(httpd ntpd).each do |pkg|
  describe package(pkg) do
    it { should be_installed }
  end
end
@RyanFrantz RyanFrantz added the bug label Sep 28, 2017
@jjustice6
Copy link

jjustice6 commented Nov 1, 2017

Note also that chefspec/chefspec#639 affects packages in particular.

You'll likely want the loop for the integration tests, but the array for unit tests.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants