First, you can set expectations on the `opkg` provider instance method, so you don't need to stub the `execute` method.

Second, I think there are two different contexts here, when the package list is absent and when it's present. Something like this could work:

```ruby
context "when the package list is absent" do
  before do
    Dir.stubs(:entries).with('/var/opkg-lists/').returns ['.', '..']  #empty, no package list
  end

  it "fetches the package list when installing" do
    @provider.expects(:opkg).with(:update)
    @provider.expects(:opkg).with("--force-overwrite", "install", @resource[:name])

    @provider.install
  end
end

context "when the package list is present" do
  before do
    Dir.stubs(:entries).with('/var/opkg-lists/').returns ['.', '..', 'lists']  #empty, no package list
  end

  it "fetches the package list when installing" do
    @provider.expects(:opkg).with(:update).never
    @provider.expects(:opkg).with("--force-overwrite", "install", @resource[:name])

    @provider.install
  end
end
```

(Although I would like to switch from instance variables to `let` blocks)