|
78 | 78 |
|
79 | 79 | describe "current_installed_version" do |
80 | 80 | it "should return the current version if the package is installed" do |
81 | | - @stdout.should_receive(:readline).and_return(" openssl @0.9.8k_0 (active)\n") |
| 81 | + @stdout.should_receive(:read).and_return(<<EOF |
| 82 | +The following ports are currently installed: |
| 83 | + openssl @0.9.8k_0 (active) |
| 84 | +EOF |
| 85 | + ) |
| 86 | + |
82 | 87 | @provider.should_receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
83 | 88 | @provider.current_installed_version.should == "0.9.8k_0" |
84 | 89 | end |
85 | 90 |
|
86 | 91 | it "should return nil if a package is not currently installed" do |
87 | | - @stdout.should_receive(:readline).and_return(" \n") |
| 92 | + @stdout.should_receive(:read).and_return(" \n") |
88 | 93 | @provider.should_receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
89 | 94 | @provider.current_installed_version.should be_nil |
90 | 95 | end |
91 | 96 | end |
92 | 97 |
|
93 | 98 | describe "macports_candidate_version" do |
94 | 99 | it "should return the latest available version of a given package" do |
95 | | - @stdout.should_receive(:readline).and_return("version: 4.2.7\n") |
| 100 | + @stdout.should_receive(:read).and_return("version: 4.2.7\n") |
96 | 101 | @provider.should_receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
97 | 102 | @provider.macports_candidate_version.should == "4.2.7" |
98 | 103 | end |
99 | 104 |
|
100 | 105 | it "should return nil if there is no version for a given package" do |
101 | | - @stdout.should_receive(:readline).and_return("Error: port fadsfadsfads not found\n") |
| 106 | + @stdout.should_receive(:read).and_return("Error: port fadsfadsfads not found\n") |
102 | 107 | @provider.should_receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
103 | 108 | @provider.macports_candidate_version.should be_nil |
104 | 109 | end |
|
127 | 132 | @provider.should_receive(:run_command).with(:command => "port uninstall zsh @4.2.7") |
128 | 133 | @provider.purge_package("zsh", "4.2.7") |
129 | 134 | end |
| 135 | + |
| 136 | + it "should purge the currently active version if no explicit version is passed in" do |
| 137 | + @provider.should_receive(:run_command).with(:command => "port uninstall zsh") |
| 138 | + @provider.purge_package("zsh", nil) |
| 139 | + end |
130 | 140 | end |
131 | 141 |
|
132 | 142 | describe "remove_package" do |
133 | 143 | it "should run the port deactivate command with the correct version" do |
134 | 144 | @provider.should_receive(:run_command).with(:command => "port deactivate zsh @4.2.7") |
135 | 145 | @provider.remove_package("zsh", "4.2.7") |
136 | 146 | end |
| 147 | + |
| 148 | + it "should remove the currently active version if no explicit version is passed in" do |
| 149 | + @provider.should_receive(:run_command).with(:command => "port deactivate zsh") |
| 150 | + @provider.remove_package("zsh", nil) |
| 151 | + end |
137 | 152 | end |
138 | 153 |
|
139 | 154 | describe "upgrade_package" do |
140 | 155 | it "should run the port upgrade command with the correct version" do |
141 | | - @current_resource.should_receive(:version).and_return("4.1.6") |
| 156 | + @current_resource.should_receive(:version).at_least(:once).and_return("4.1.6") |
142 | 157 | @provider.current_resource = @current_resource |
| 158 | + |
143 | 159 | @provider.should_receive(:run_command).with(:command => "port upgrade zsh @4.2.7") |
144 | 160 |
|
145 | 161 | @provider.upgrade_package("zsh", "4.2.7") |
146 | 162 | end |
147 | 163 |
|
148 | 164 | it "should not run the port upgrade command if the version is already installed" do |
149 | | - @current_resource.should_receive(:version).and_return("4.2.7") |
| 165 | + @current_resource.should_receive(:version).at_least(:once).and_return("4.2.7") |
150 | 166 | @provider.current_resource = @current_resource |
151 | 167 | @provider.should_not_receive(:run_command) |
152 | 168 |
|
153 | 169 | @provider.upgrade_package("zsh", "4.2.7") |
154 | 170 | end |
| 171 | + |
| 172 | + it "should call install_package if the package isn't currently installed" do |
| 173 | + @current_resource.should_receive(:version).at_least(:once).and_return(nil) |
| 174 | + @provider.current_resource = @current_resource |
| 175 | + @provider.should_receive(:install_package).and_return(true) |
| 176 | + |
| 177 | + @provider.upgrade_package("zsh", "4.2.7") |
| 178 | + end |
155 | 179 | end |
156 | 180 | end |
0 commit comments