|
123 | 123 | end |
124 | 124 |
|
125 | 125 | describe ".add_command" do |
126 | | - it "adds a command" do |
| 126 | + after {RDF::CLI::COMMANDS.delete(:foo)} |
| 127 | + |
| 128 | + it "adds a command with block" do |
127 | 129 | RDF::CLI.add_command(:foo) do |argv, opts| |
128 | 130 | $stdout.puts "Hello, World!" |
129 | 131 | end |
130 | 132 | expect {RDF::CLI.exec(["foo"])}.to write("Hello, World!").to(:output) |
131 | 133 | end |
| 134 | + |
| 135 | + it "adds a command with lambda option" do |
| 136 | + lambda = ->(argv, opts) do |
| 137 | + $stdout.puts "Hello, World!" |
| 138 | + end |
| 139 | + RDF::CLI.add_command(:foo, lambda: lambda) |
| 140 | + expect {RDF::CLI.exec(["foo"])}.to write("Hello, World!").to(:output) |
| 141 | + end |
| 142 | + |
| 143 | + it "calls command with repository" do |
| 144 | + RDF::CLI.add_command(:foo) do |argv, opts| |
| 145 | + expect(opts).to include(repository: kind_of(RDF::Enumerable)) |
| 146 | + end |
| 147 | + RDF::CLI.exec(["foo"]) |
| 148 | + end |
| 149 | + |
| 150 | + it "calls command with specified repository" do |
| 151 | + repo = double(:repo) |
| 152 | + RDF::CLI.add_command(:foo, repository: repo) do |argv, opts| |
| 153 | + expect(opts).to include(repository: repo) |
| 154 | + end |
| 155 | + RDF::CLI.exec(["foo"]) |
| 156 | + end |
132 | 157 | end |
133 | 158 |
|
134 | 159 | context "commands" do |
|
215 | 240 | end |
216 | 241 |
|
217 | 242 | it "complains if filtered command is attempted" do |
218 | | - RDF::CLI.add_command(:foo, filter: {output_format: :nquads}) |
| 243 | + RDF::CLI.add_command(:filtered, filter: {output_format: :nquads}) |
219 | 244 | expect do |
220 | 245 | expect do |
221 | | - RDF::CLI.exec(["foo"], output_format: :ntriples) |
| 246 | + RDF::CLI.exec(["filtered"], output_format: :ntriples) |
222 | 247 | end.to raise_error(ArgumentError) |
223 | | - end.to write(%(Command "foo" requires output_format: nquads, not ntriples)).to(:output) |
| 248 | + end.to write(%(Command "filtered" requires output_format: nquads, not ntriples)).to(:output) |
| 249 | + end |
| 250 | + |
| 251 | + it "uses repository specified in command" do |
| 252 | + RDF::CLI.add_command(:with_repo, repository: double(:repo)) |
224 | 253 | end |
225 | 254 |
|
226 | 255 | context "chaining" do |
|
0 commit comments