serverspec/specinfra — pull request #227 by Nowaker (2014-09-27 20:07:19+00:00)
Title: Use `pacman -Q` correctly to check for package name and version

`pacman -Q | grep package_name` makes this pass:

```
describe package('lib') do
it { should be_installed }
end
```

`pacman -Q package_name` is the way to go.

Also, version checking was totally broken. In `grep package_name version` command `version` is treated as a file name.

```
describe package('zsh') do
it { should be_installed.with_version('5.0.6') }
end

grep: 5.0.6: No such file or directory
```

I fixed it, and introduced two options:

- '5.0.6' - will check for this particular version of software
- '5.0.6-1' - not only version of the software but also with an explicit [pkgrel](https://wiki.archlinux.org/index.php/PKGBUILD#pkgrel)

I'd be happy to write unit tests for all I did but I don't know how. Can you help please? Now it's tested in-place:

```
describe package('lib') do
it { should_not be_installed }
end

describe package('zsh') do
it { should_not be_installed.with_version('5.0.5') }
end

describe package('zsh') do
it { should_not be_installed.with_version('5.0') }
end

describe package('zsh') do
it { should_not be_installed.with_version('0.5') }
end

describe package('zsh') do
it { should be_installed.with_version('5.0.6') }
end

describe package('zsh') do
it { should be_installed.with_version('5.0.6-1') }
end

describe package('zsh') do
it { should_not be_installed.with_version('5.0.6-2') }
end
```

By the way, `get_package_version` method isn't right too, but I'll fix it in a separate pull request. I have to find the best way to avoid the code duplication between `check_installed` and `get_pachage_version` first. :-)

```
def get_package_version(package, opts=nil)
"pacman -Q #{escape(package)} | grep Version | awk '{print $3}'"
end
```

Also, please enable issues in your repository. I have two different problems in Arch Linux I'd like to report that I don't know how to fix, hence I'm not able to submit a patch. At least without your help.