spec/lib/hackpad/cli/store_spec.rb in hackpad-cli-0.0.6 vs spec/lib/hackpad/cli/store_spec.rb in hackpad-cli-0.0.7
- old
+ new
@@ -3,25 +3,51 @@
require 'spec_helper'
require "hackpad/cli/store"
describe Hackpad::Cli::Store do
+ let(:configdir) { File.expand_path('../../../../files', __FILE__) }
+ let(:options) { { configdir: configdir, workspace: 'default' } }
+
before :each do
- options = {
- "configdir" => File.expand_path('../../../files', __FILE__),
- "workspace" => 'default'
- }
- Hackpad::Cli::Store.prepare options
+ subject.prepare options
end
- it "reads pads list from file" do
- File.stub(:read).and_return("gy23ui first one\ngy3u4 second one\n23489g third")
- list = Hackpad::Cli::Store.read_list
- expect(list).to be_an Array
- expect(list[0]).to be_an OpenStruct
- expect(list[0].id).to eq "gy23ui"
- expect(list[0].title).to eq "first one"
- expect(list[2].id).to eq "23489g"
- expect(list[2].title).to eq "third"
+ describe ".read_list" do
+ before { File.stub(:read).and_return("gy23ui first one\ngy3u4 second one\n23489g [some time] third") }
+ let(:list) { subject.read_list }
+ it { expect(list).to be_an Array }
+ it { expect(list[0]).to be_an OpenStruct }
+ it { expect(list[0].id).to eq "gy23ui" }
+ it { expect(list[0].title).to eq "first one" }
+ it { expect(list[2].id).to eq "23489g" }
+ it { expect(list[2].title).to eq "third" }
+ it { expect(list[2].cached_at).to eq "some time" }
+ end
+
+ describe ".exists?" do
+
+ context "when refresh option is set," do
+ let(:options) { { configdir: configdir, workspace: 'default', refresh: true } }
+ before {
+ subject.prepare options
+ FileUtils.touch File.join(configdir, 'default', 'pads', 'txt', 'xxx')
+ }
+ after { FileUtils.rm File.join(configdir, 'default', 'pads', 'txt', 'xxx') }
+ it { expect(subject.exists? 'txt', 'xxx').to be false }
+ end
+
+ context "when refresh option is not set," do
+ context "when config file don't exist," do
+ it { expect(subject.exists? 'txt', 'xxx').to be false }
+ end
+
+ context "when configfile exists," do
+ before { FileUtils.touch File.join(configdir, 'default', 'pads', 'txt', 'xxx') }
+ after { FileUtils.rm File.join(configdir, 'default', 'pads', 'txt', 'xxx') }
+ it { expect(subject.exists? 'txt', 'xxx').to be true }
+ end
+ end
+
end
end