Best Rr_ruby code snippet using Project.run_command
punch_command_spec.rb
Source:punch_command_spec.rb
1require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')2def run_command(*args)3 Object.const_set(:ARGV, args)4 begin5 eval File.read(File.join(File.dirname(__FILE__), *%w[.. bin punch]))6 rescue SystemExit7 end8end9describe 'punch command' do10 before do11 [:ARGV, :OPTIONS, :MANDATORY_OPTIONS].each do |const|12 Object.send(:remove_const, const) if Object.const_defined?(const)13 end14 15 self.stub!(:puts)16 Punch.stub!(:load)17 Punch.stub!(:write)18 19 @project = 'myproj'20 end21 22 it 'should exist' do23 lambda { run_command }.should.not.raise(Errno::ENOENT)24 end25 26 it 'should require a command' do27 self.should.receive(:puts) do |output|28 output.should.match(/usage.+command/i)29 end30 run_command31 end32 33 describe "when the command is 'total'" do34 before do35 Punch.stub!(:total)36 end37 38 it 'should load punch data' do39 Punch.should.receive(:load)40 run_command('total', @project)41 end42 43 it 'should get the total for the requested project' do44 Punch.should.receive(:total) do |proj, _|45 proj.should == @project46 end47 run_command('total', @project)48 end49 50 it 'should get the total for all projects if none given' do51 Punch.should.receive(:total) do |proj, _|52 proj.should.be.nil53 end54 run_command('total')55 end56 57 it 'should output the total' do58 result = 'total data'59 Punch.stub!(:total).and_return(result)60 self.should.receive(:puts).with(result.inspect)61 run_command('total', @project)62 end63 64 it 'should output the total as YAML if the total data is a Hash' do65 result = { :some_project => 'total data', :some_other_project => 'other total data' }66 Punch.stub!(:total).and_return(result)67 self.should.receive(:puts).with(result.to_yaml)68 run_command('total', @project)69 end70 71 it 'should not write the data' do72 Punch.should.receive(:write).never73 run_command('total')74 end75 76 describe 'when options specified' do77 it "should pass on an 'after' time option given by --after" do78 time_option = '2008-08-26 09:47'79 time = Time.local(2008, 8, 26, 9, 47)80 Punch.should.receive(:total) do |proj, options|81 proj.should == @project82 options[:after].should == time83 end84 run_command('total', @project, '--after', time_option)85 end86 87 it "should pass on a 'before' time option given by --before" do88 time_option = '2008-08-23 15:39'89 time = Time.local(2008, 8, 23, 15, 39)90 Punch.should.receive(:total) do |proj, options|91 proj.should == @project92 options[:before].should == time93 end94 run_command('total', @project, '--before', time_option)95 end96 97 it 'should handle a time option given as a date' do98 time_option = '2008-08-23'99 time = Time.local(2008, 8, 23)100 Punch.should.receive(:total) do |proj, options|101 proj.should == @project102 options[:before].should == time103 end104 run_command('total', @project, '--before', time_option)105 end106 107 it 'should accept time options if no project given' do108 time_option = '2008-08-26 09:47'109 time = Time.local(2008, 8, 26, 9, 47)110 Punch.should.receive(:total) do |proj, options|111 proj.should.be.nil112 options[:before].should == time113 end114 run_command('total', '--before', time_option)115 end116 117 it "should pass on an 'on' date option given by --on" do118 date_option = '2008-08-23'119 date = Date.new(2008, 8, 23)120 Punch.should.receive(:total) do |proj, options|121 proj.should == @project122 options[:on].should == date123 end124 run_command('total', @project, '--on', date_option)125 end126 127 it 'should also pass the formatting option' do128 time_option = '2008-08-26 09:47'129 Punch.should.receive(:total) do |proj, options|130 proj.should == @project131 options[:format].should == true132 end133 run_command('total', @project, '--before', time_option)134 end135 end136 137 it 'should pass only the formatting option if no options specified' do138 Punch.should.receive(:total) do |proj, options|139 proj.should == @project140 options[:format].should == true141 end142 run_command('total', @project)143 end144 end145 describe "when the command is 'status'" do146 before do147 Punch.stub!(:status)148 end149 150 it 'should load punch data' do151 Punch.should.receive(:load)152 run_command('status', @project)153 end154 155 it 'should get the status for the requested project' do156 Punch.should.receive(:status).with(@project, {})157 run_command('status', @project)158 end159 160 it 'should get the status for all projects if none given' do161 Punch.should.receive(:status).with(nil, {})162 run_command('status')163 end164 165 it 'should output the status' do166 result = 'status data'167 Punch.stub!(:status).and_return(result)168 self.should.receive(:puts).with(result.inspect)169 run_command('status', @project)170 end171 172 it "should output the status as YAML if the status data is a Hash" do173 result = { 'status' => 'data' }174 Punch.stub!(:status).and_return(result)175 self.should.receive(:puts).with(result.to_yaml)176 run_command('status')177 end178 179 it 'should pass a true full option if specified on the command line (with --full)' do180 Punch.should.receive(:status).with(@project, :full => true)181 run_command('status', @project, '--full')182 end183 184 it 'should pass a true full option if specified on the command line (with --full) and no project given' do185 Punch.should.receive(:status).with(nil, :full => true)186 run_command('status', '--full')187 end188 189 it 'should pass a true short option if specified on the command line (with --short)' do190 Punch.should.receive(:status).with(@project, :short => true)191 run_command('status', @project, '--short')192 end193 194 it 'should pass a true short option if specified on the command line (with --short) and no project given' do195 Punch.should.receive(:status).with(nil, :short => true)196 run_command('status', '--short')197 end198 199 it 'should handle both --short and --full options together' do200 Punch.should.receive(:status).with(nil, :short => true, :full => true)201 run_command('status', '--short', '--full')202 end203 204 it 'should not write the data' do205 Punch.should.receive(:write).never206 run_command('status')207 end208 end209 210 describe "when the command is 'in'" do211 before do212 Punch.stub!(:in)213 end214 215 it 'should load punch data' do216 Punch.should.receive(:load)217 run_command('in', @project)218 end219 220 it 'should punch in to the given project' do221 Punch.should.receive(:in).with(@project, {})222 run_command('in', @project)223 end224 225 it 'should pass a time if specified on the command line (with --time)' do226 time_option = '2008-08-23 15:39'227 time = Time.local(2008, 8, 23, 15, 39)228 Punch.should.receive(:in) do |proj, options|229 proj.should == @project230 options[:time].should == time231 end232 run_command('in', @project, '--time', time_option)233 end234 235 it 'should pass a time if specified on the command line (with --at)' do236 time_option = '2008-08-23 15:39'237 time = Time.local(2008, 8, 23, 15, 39)238 Punch.should.receive(:in) do |proj, options|239 proj.should == @project240 options[:time].should == time241 end242 run_command('in', @project, '--at', time_option)243 end244 245 it 'should pass a message if specified on the command line (with --message)' do246 message = 'About to do some amazing work'247 Punch.should.receive(:in) do |proj, options|248 proj.should == @project249 options[:message].should == message250 end251 run_command('in', @project, '--message', message)252 end253 254 it 'should pass a message if specified on the command line (with -m)' do255 message = 'About to do some amazing work'256 Punch.should.receive(:in) do |proj, options|257 proj.should == @project258 options[:message].should == message259 end260 run_command('in', @project, '-m', message)261 end262 263 describe 'when punched in successfully' do264 before do265 Punch.stub!(:in).and_return(true)266 end267 268 it 'should write the data' do269 Punch.should.receive(:write)270 run_command('in', @project)271 end272 273 it 'should not print anything' do274 self.should.receive(:puts).never275 run_command('in', @project)276 end277 end278 279 describe 'when not punched in successfully' do280 before do281 Punch.stub!(:in).and_return(false)282 end283 284 it 'should not write the data' do285 Punch.should.receive(:write).never286 run_command('in', @project)287 end288 289 it 'should print a message' do290 self.should.receive(:puts) do |output|291 output.should.match(/already.+in/i)292 end293 run_command('in', @project)294 end295 end296 297 describe 'when no project given' do298 it 'should display an error message' do299 self.should.receive(:puts) do |output|300 output.should.match(/project.+require/i)301 end302 run_command('in')303 end304 305 it 'should not punch in' do306 Punch.stub!(:write)307 Punch.should.receive(:in).never308 run_command('in')309 end310 311 it 'should not write the data' do312 Punch.should.receive(:write).never313 run_command('in')314 end315 end316 end317 describe "when the command is 'out'" do318 before do319 Punch.stub!(:out)320 end321 322 it 'should load punch data' do323 Punch.should.receive(:load)324 run_command('out', @project)325 end326 327 it 'should punch out of the given project' do328 Punch.should.receive(:out).with(@project, {})329 run_command('out', @project)330 end331 332 it 'should pass a time if specified on the command line (with --time)' do333 time_option = '2008-08-23 15:39'334 time = Time.local(2008, 8, 23, 15, 39)335 Punch.should.receive(:out) do |proj, options|336 proj.should == @project337 options[:time].should == time338 end339 run_command('out', @project, '--time', time_option)340 end341 342 it 'should pass a time if specified on the command line (with --at)' do343 time_option = '2008-08-23 15:39'344 time = Time.local(2008, 8, 23, 15, 39)345 Punch.should.receive(:out) do |proj, options|346 proj.should == @project347 options[:time].should == time348 end349 run_command('out', @project, '--at', time_option)350 end351 352 it 'should pass a message if specified on the command line (with --message)' do353 message = 'Finished doing some stellar work'354 Punch.should.receive(:out) do |proj, options|355 proj.should == @project356 options[:message].should == message357 end358 run_command('out', @project, '--message', message)359 end360 361 it 'should pass a message if specified on the command line (with -m)' do362 message = 'Finished doing some stellar work'363 Punch.should.receive(:out) do |proj, options|364 proj.should == @project365 options[:message].should == message366 end367 run_command('out', @project, '-m', message)368 end369 370 describe 'if no project given' do371 it 'should punch out of all projects' do372 Punch.should.receive(:out).with(nil, {})373 run_command('out')374 end375 376 it 'should pass a time if specified on the command line (with --time)' do377 time_option = '2008-08-23 15:39'378 time = Time.local(2008, 8, 23, 15, 39)379 Punch.should.receive(:out) do |proj, options|380 proj.should.be.nil381 options[:time].should == time382 end383 run_command('out', '--time', time_option)384 end385 386 it 'should pass a time if specified on the command line (with --at)' do387 time_option = '2008-08-23 15:39'388 time = Time.local(2008, 8, 23, 15, 39)389 Punch.should.receive(:out) do |proj, options|390 proj.should.be.nil391 options[:time].should == time392 end393 run_command('out', '--at', time_option)394 end395 396 it 'should pass a message if specified on the command line (with --message)' do397 message = 'Finished doing some stellar work'398 Punch.should.receive(:out) do |proj, options|399 proj.should.be.nil400 options[:message].should == message401 end402 run_command('out', '--message', message)403 end404 405 it 'should pass a message if specified on the command line (with -m)' do406 message = 'Finished doing some stellar work'407 Punch.should.receive(:out) do |proj, options|408 proj.should.be.nil409 options[:message].should == message410 end411 run_command('out', '-m', message)412 end413 end414 415 describe 'when punched out successfully' do416 before do417 Punch.stub!(:out).and_return(true)418 end419 420 it 'should write the data' do421 Punch.should.receive(:write)422 run_command('out', @project)423 end424 425 it 'should not print anything' do426 self.should.receive(:puts).never427 run_command('out', @project)428 end429 430 describe 'and no project given' do431 it 'should not print anything' do432 self.should.receive(:puts).never433 run_command('out')434 end435 end436 end437 438 describe 'when not punched out successfully' do439 before do440 Punch.stub!(:out).and_return(false)441 end442 443 it 'should not write the data' do444 Punch.should.receive(:write).never445 run_command('out', @project)446 end447 448 it 'should print a message' do449 self.should.receive(:puts) do |output|450 output.should.match(/already.+out/i)451 end452 run_command('out', @project)453 end454 455 describe 'and no project given' do456 it 'should print a message' do457 self.should.receive(:puts) do |output|458 output.should.match(/already.+out/i)459 end460 run_command('out')461 end462 end463 end464 end465 describe "when the command is 'entry'" do466 before do467 Punch.stub!(:entry)468 @from_option = '2012-04-10 14:39'469 @to_option = '2012-04-10 17:43'470 end471 it 'should load punch data' do472 Punch.should.receive(:load)473 run_command('entry', @project)474 end475 it 'should make a punch entry for the given project' do476 from_option = '2012-04-10 14:39'477 from_time = Time.local(2012, 4, 10, 14, 39)478 to_option = '2012-04-10 17:43'479 to_time = Time.local(2012, 4, 10, 17, 43)480 Punch.should.receive(:entry) do |proj, options|481 proj.should == @project482 options[:from].should == from_time483 options[:to ].should == to_time484 end485 run_command('entry', @project, '--from', from_option, '--to', to_option)486 end487 it 'should pass a message if specified on the command line (with --message)' do488 message = 'About to do some amazing work'489 Punch.should.receive(:entry) do |proj, options|490 proj.should == @project491 options[:message].should == message492 end493 run_command('entry', @project, '--from', @from_option, '--to', @to_option, '--message', message)494 end495 it 'should pass a message if specified on the command line (with -m)' do496 message = 'About to do some amazing work'497 Punch.should.receive(:entry) do |proj, options|498 proj.should == @project499 options[:message].should == message500 end501 run_command('entry', @project, '--from', @from_option, '--to', @to_option, '-m', message)502 end503 describe 'when entry created successfully' do504 before do505 Punch.stub!(:entry).and_return(true)506 end507 it 'should write the data' do508 Punch.should.receive(:write)509 run_command('entry', @project, '--from', @from_option, '--to', @to_option)510 end511 it 'should not print anything' do512 self.should.receive(:puts).never513 run_command('entry', @project, '--from', @from_option, '--to', @to_option)514 end515 end516 describe 'when entry not created successfully' do517 before do518 Punch.stub!(:entry).and_return(false)519 end520 it 'should not write the data' do521 Punch.should.receive(:write).never522 run_command('entry', @project, '--from', @from_option, '--to', @to_option)523 end524 it 'should print a message' do525 self.should.receive(:puts) do |output|526 output.should.match(/cannot.+entry/i)527 end528 run_command('entry', @project, '--from', @from_option, '--to', @to_option)529 end530 end531 describe 'when no project given' do532 it 'should display an error message' do533 self.should.receive(:puts) do |output|534 output.should.match(/project.+require/i)535 end536 run_command('entry')537 end538 it 'should not create an entry' do539 Punch.stub!(:write)540 Punch.should.receive(:entry).never541 run_command('entry')542 end543 it 'should not write the data' do544 Punch.should.receive(:write).never545 run_command('entry')546 end547 end548 it "should have 'clock' as an alias" do549 from_option = '2012-04-10 14:39'550 from_time = Time.local(2012, 4, 10, 14, 39)551 to_option = '2012-04-10 17:43'552 to_time = Time.local(2012, 4, 10, 17, 43)553 Punch.should.receive(:entry) do |proj, options|554 proj.should == @project555 options[:from].should == from_time556 options[:to ].should == to_time557 end558 run_command('clock', @project, '--from', from_option, '--to', to_option)559 end560 end561 describe "when the command is 'delete'" do562 before do563 Punch.stub!(:delete)564 end565 566 it 'should load punch data' do567 Punch.should.receive(:load)568 run_command('delete', @project)569 end570 571 it 'should delete the given project' do572 Punch.stub!(:write)573 Punch.should.receive(:delete).with(@project)574 run_command('delete', @project)575 end576 577 it 'should output the result' do578 result = 'result'579 Punch.stub!(:delete).and_return(result)580 self.should.receive(:puts).with(result.inspect)581 run_command('delete', @project)582 end583 584 describe 'when deleted successfully' do585 it 'should write the data' do586 Punch.stub!(:delete).and_return(true)587 Punch.should.receive(:write)588 run_command('delete', @project)589 end590 end591 592 describe 'when not deleted successfully' do593 it 'should not write the data' do594 Punch.stub!(:delete).and_return(nil)595 Punch.should.receive(:write).never596 run_command('delete', @project)597 end598 end599 600 describe 'when no project given' do601 it 'should display an error message' do602 self.should.receive(:puts) do |output|603 output.should.match(/project.+require/i)604 end605 run_command('delete')606 end607 608 it 'should not delete' do609 Punch.stub!(:write)610 Punch.should.receive(:delete).never611 run_command('delete')612 end613 614 it 'should not write the data' do615 Punch.should.receive(:write).never616 run_command('delete')617 end618 end619 end620 621 describe "when the command is 'log'" do622 before do623 Punch.stub!(:log)624 @message = 'log message'625 end626 627 it 'should load punch data' do628 Punch.should.receive(:load)629 run_command('log', @project, @message)630 end631 632 it 'should log a message for the given project' do633 Punch.stub!(:write)634 Punch.should.receive(:log).with(@project, @message, {})635 run_command('log', @project, @message)636 end637 638 it 'should accept a message specified with --message' do639 Punch.stub!(:write)640 Punch.should.receive(:log).with(@project, @message, {})641 run_command('log', @project, '--message', @message)642 end643 644 it 'should accept a message specified with -m' do645 Punch.stub!(:write)646 Punch.should.receive(:log).with(@project, @message, {})647 run_command('log', @project, '-m', @message)648 end649 650 it 'should use the message option specified with --message over the command-line argument' do651 other_message = 'some other message'652 Punch.stub!(:write)653 Punch.should.receive(:log).with(@project, other_message, {})654 run_command('log', @project, @message, '-m', other_message)655 end656 657 it 'should pass a time if specified on the command line (with --time)' do658 time_option = '2008-08-23 15:39'659 time = Time.local(2008, 8, 23, 15, 39)660 Punch.should.receive(:log) do |proj, msg, options|661 proj.should == @project662 msg.should == @message663 options[:time].should == time664 end665 run_command('log', @project, @message, '--time', time_option)666 end667 668 it 'should pass a time if specified on the command line (with --at)' do669 time_option = '2008-08-23 15:39'670 time = Time.local(2008, 8, 23, 15, 39)671 Punch.should.receive(:log) do |proj, msg, options|672 proj.should == @project673 msg.should == @message674 options[:time].should == time675 end676 run_command('log', @project, @message, '--at', time_option)677 end678 679 describe 'when logged successfully' do680 before do681 Punch.stub!(:log).and_return(true)682 end683 684 it 'should write the data' do685 Punch.should.receive(:write)686 run_command('log', @project, @message)687 end688 689 it 'should not print anything' do690 self.should.receive(:puts).never691 run_command('log', @project, @message)692 end693 end694 695 describe 'when not logged successfully' do696 before do697 Punch.stub!(:log).and_return(false)698 end699 700 it 'should not write the data' do701 Punch.should.receive(:write).never702 run_command('log', @project, @message)703 end704 705 it 'should print a message' do706 self.should.receive(:puts) do |output|707 output.should.match(/not.+in/i)708 end709 run_command('log', @project, @message)710 end711 end712 713 describe 'when no project given' do714 it 'should display an error message' do715 self.should.receive(:puts) do |output|716 output.should.match(/project.+require/i)717 end718 run_command('log')719 end720 721 it 'should not log' do722 Punch.stub!(:write)723 Punch.should.receive(:log).never724 run_command('log')725 end726 727 it 'should not write the data' do728 Punch.should.receive(:write).never729 run_command('log')730 end731 end732 733 describe 'when no message given' do734 it 'should display an error message' do735 self.should.receive(:puts) do |output|736 output.should.match(/message.+require/i)737 end738 run_command('log', @project)739 end740 741 it 'should not log' do742 Punch.stub!(:write)743 Punch.should.receive(:log).never744 run_command('log', @project)745 end746 747 it 'should not write the data' do748 Punch.should.receive(:write).never749 run_command('log', @project)750 end751 end752 end753 754 describe "when the command is 'list'" do755 before do756 Punch.stub!(:list)757 end758 759 it 'should load punch data' do760 Punch.should.receive(:load)761 run_command('list', @project)762 end763 764 it 'should get the data for the requested project' do765 Punch.should.receive(:list) do |proj, _|766 proj.should == @project767 end768 run_command('list', @project)769 end770 771 it 'should get the data for all projects if none given' do772 Punch.should.receive(:list) do |proj, _|773 proj.should.be.nil774 end775 run_command('list')776 end777 778 it 'should output the list data' do779 result = 'list data'780 Punch.stub!(:list).and_return(result)781 self.should.receive(:puts).with(result.to_yaml)782 run_command('list')783 end784 785 describe 'when options specified' do786 it "should pass on an 'after' time option given by --after" do787 time_option = '2008-08-26 09:47'788 time = Time.local(2008, 8, 26, 9, 47)789 Punch.should.receive(:list) do |proj, options|790 proj.should == @project791 options[:after].should == time792 end793 run_command('list', @project, '--after', time_option)794 end795 796 it "should pass on a 'before' time option given by --before" do797 time_option = '2008-08-23 15:39'798 time = Time.local(2008, 8, 23, 15, 39)799 Punch.should.receive(:list) do |proj, options|800 proj.should == @project801 options[:before].should == time802 end803 run_command('list', @project, '--before', time_option)804 end805 806 it 'should handle a time option given as a date' do807 time_option = '2008-08-23'808 time = Time.local(2008, 8, 23)809 Punch.should.receive(:list) do |proj, options|810 proj.should == @project811 options[:before].should == time812 end813 run_command('list', @project, '--before', time_option)814 end815 816 it 'should accept time options if no project given' do817 time_option = '2008-08-26 09:47'818 time = Time.local(2008, 8, 26, 9, 47)819 Punch.should.receive(:list) do |proj, options|820 proj.should.be.nil821 options[:before].should == time822 end823 run_command('list', '--before', time_option)824 end825 826 it "should pass on an 'on' date option given by --on" do827 date_option = '2008-08-23'828 date = Date.new(2008, 8, 23)829 Punch.should.receive(:list) do |proj, options|830 proj.should == @project831 options[:on].should == date832 end833 run_command('list', @project, '--on', date_option)834 end835 end836 837 it 'should not write the data' do838 Punch.should.receive(:write).never839 run_command('list')840 end841 end842 843 describe "when the command is 'summary'" do844 before do845 Punch.stub!(:summary)846 end847 848 it 'should load punch data' do849 Punch.should.receive(:load)850 run_command('summary', @project)851 end852 853 it 'should get the summary for the requested project' do854 Punch.should.receive(:summary) do |proj, _|855 proj.should == @project856 end857 run_command('summary', @project)858 end859 860 it 'should output the summary' do861 result = 'summary data'862 Punch.stub!(:summary).and_return(result)863 self.should.receive(:puts).with(result.to_yaml)864 run_command('summary', @project)865 end866 867 describe 'when options specified' do868 it "should pass on an 'after' time option given by --after" do869 time_option = '2008-08-26 09:47'870 time = Time.local(2008, 8, 26, 9, 47)871 Punch.should.receive(:summary) do |proj, options|872 proj.should == @project873 options[:after].should == time874 end875 run_command('summary', @project, '--after', time_option)876 end877 878 it "should pass on a 'before' time option given by --before" do879 time_option = '2008-08-23 15:39'880 time = Time.local(2008, 8, 23, 15, 39)881 Punch.should.receive(:summary) do |proj, options|882 proj.should == @project883 options[:before].should == time884 end885 run_command('summary', @project, '--before', time_option)886 end887 888 it 'should handle a time option given as a date' do889 time_option = '2008-08-23'890 time = Time.local(2008, 8, 23)891 Punch.should.receive(:summary) do |proj, options|892 proj.should == @project893 options[:before].should == time894 end895 run_command('summary', @project, '--before', time_option)896 end897 898 it "should pass on an 'on' date option given by --on" do899 date_option = '2008-08-23'900 date = Date.new(2008, 8, 23)901 Punch.should.receive(:summary) do |proj, options|902 proj.should == @project903 options[:on].should == date904 end905 run_command('summary', @project, '--on', date_option)906 end907 908 it 'should also pass the formatting option' do909 time_option = '2008-08-23'910 Punch.should.receive(:summary) do |proj, options|911 proj.should == @project912 options[:format].should == true913 end914 run_command('summary', @project, '--before', time_option)915 end916 end917 918 it 'should pass only the formatting option if no options specified' do919 Punch.should.receive(:summary) do |proj, options|920 proj.should == @project921 options[:format].should == true922 end923 run_command('summary', @project)924 end925 926 it 'should not write the data' do927 Punch.should.receive(:write).never928 run_command('summary')929 end930 931 describe 'when no project given' do932 it 'should display an error message' do933 self.should.receive(:puts) do |output|934 output.should.match(/project.+require/i)935 end936 run_command('summary')937 end938 it 'should not get a summary' do939 Punch.should.receive(:summary).never940 run_command('summary')941 end942 end943 end944 945 describe "when the command is 'age'" do946 before do947 Punch.stub!(:age)948 end949 950 it 'should load punch data' do951 Punch.should.receive(:load)952 run_command('age', @project)953 end954 955 it 'should age the given project' do956 Punch.stub!(:write)957 Punch.should.receive(:age) do |proj, _|958 proj.should == @project959 end960 run_command('age', @project)961 end962 963 describe 'when options specified' do964 it "should pass on a 'before' time option given by --before" do965 time_option = '2008-08-23 15:39'966 time = Time.local(2008, 8, 23, 15, 39)967 Punch.should.receive(:age) do |proj, options|968 proj.should == @project969 options[:before].should == time970 end971 run_command('age', @project, '--before', time_option)972 end973 974 it 'should handle a time option given as a date' do975 time_option = '2008-08-23'976 time = Time.local(2008, 8, 23)977 Punch.should.receive(:age) do |proj, options|978 proj.should == @project979 options[:before].should == time980 end981 run_command('age', @project, '--before', time_option)982 end983 end984 985 it 'should output the result' do986 result = 'result'987 Punch.stub!(:age).and_return(result)988 self.should.receive(:puts).with(result.inspect)989 run_command('age', @project)990 end991 992 describe 'when aged successfully' do993 it 'should write the data' do994 Punch.stub!(:age).and_return(true)995 Punch.should.receive(:write)996 run_command('age', @project)997 end998 end999 1000 describe 'when not aged successfully' do1001 it 'should not write the data' do1002 Punch.stub!(:age).and_return(nil)1003 Punch.should.receive(:write).never1004 run_command('age', @project)1005 end1006 end1007 1008 describe 'when no project given' do1009 it 'should display an error message' do1010 self.should.receive(:puts) do |output|1011 output.should.match(/project.+require/i)1012 end1013 run_command('age')1014 end1015 1016 it 'should not age' do1017 Punch.stub!(:write)1018 Punch.should.receive(:age).never1019 run_command('age')1020 end1021 1022 it 'should not write the data' do1023 Punch.should.receive(:write).never1024 run_command('age')1025 end1026 end1027 end1028 1029 describe 'when the command is unknown' do1030 it 'should not error' do1031 lambda { run_command('bunk') }.should.not.raise1032 end1033 1034 it 'should print a message' do1035 self.should.receive(:puts) do |output|1036 output.should.match(/command.+unknown/i)1037 end1038 run_command('bunk')1039 end1040 1041 it 'should not write the data' do1042 Punch.should.receive(:write).never1043 run_command('bunk')1044 end1045 1046 it 'should not run any punch command' do1047 [:in, :out, :delete, :status, :total, :log, :list, :summary, :age].each do |command|1048 Punch.should.receive(command).never1049 end1050 run_command('bunk')1051 end1052 end1053end...
init_spec.rb
Source:init_spec.rb
2require 'xcodeproj'3module Pod4 describe Command::Init do5 it 'complains if project does not exist' do6 lambda { run_command('init') }.should.raise Informative7 lambda { run_command('init', 'foo.xcodeproj') }.should.raise CLAide::Help8 end9 it 'complains if wrong parameters' do10 lambda { run_command('too', 'many') }.should.raise CLAide::Help11 end12 it 'complains if more than one project exists and none is specified' do13 Dir.chdir(temporary_directory) do14 Xcodeproj::Project.new(temporary_directory + 'test2.xcodeproj').save15 Xcodeproj::Project.new(temporary_directory + 'test1.xcodeproj').save16 lambda { run_command('init') }.should.raise Informative17 end18 end19 it 'complains if a Podfile already exists' do20 Dir.chdir(temporary_directory) do21 (Pathname.pwd + 'Podfile').open('w') { |f| f << "pod 'AFNetworking'" }22 Xcodeproj::Project.new(temporary_directory + 'test1.xcodeproj').save23 lambda { run_command('init') }.should.raise Informative24 end25 end26 it 'creates a Podfile for a project in current directory' do27 Dir.chdir(temporary_directory) do28 Xcodeproj::Project.new(temporary_directory + 'test1.xcodeproj').save29 run_command('init')30 Pathname.new(temporary_directory + 'Podfile').exist?.should == true31 end32 end33 it 'creates a Podfile for a specified project' do34 Dir.chdir(temporary_directory) do35 Xcodeproj::Project.new(temporary_directory + 'test1.xcodeproj').save36 Xcodeproj::Project.new(temporary_directory + 'test2.xcodeproj').save37 run_command('init', 'test2.xcodeproj')38 Pathname.new(temporary_directory + 'Podfile').exist?.should == true39 config.podfile.nil?.should == false40 end41 end42 it 'creates a Podfile with targets from the project' do43 Dir.chdir(temporary_directory) do44 project = Xcodeproj::Project.new(temporary_directory + 'test.xcodeproj')45 project.new_target(:application, 'AppA', :ios)46 project.new_target(:application, 'AppB', :ios)47 project.new_target(:application, "App'C", :ios)48 project.new_aggregate_target('Aggregate')49 project.save50 run_command('init')51 config.podfile.should.not.be.nil52 config.podfile.target_definitions.length.should == project.targets.length53 config.podfile.target_definitions['AppA'].should.not.be.nil54 config.podfile.target_definitions['AppB'].should.not.be.nil55 config.podfile.target_definitions["App'C"].should.not.be.nil56 config.podfile.target_definitions['Aggregate'].should.be.nil57 end58 end59 it 'includes default pods in a Podfile' do60 Dir.chdir(temporary_directory) do61 tmp_templates_dir = Pathname.pwd + 'templates_dir'62 tmp_templates_dir.mkpath63 config.stubs(:templates_dir).returns(tmp_templates_dir)64 open(config.default_podfile_path, 'w') { |f| f << "pod 'AFNetworking'" }65 project = Xcodeproj::Project.new(temporary_directory + 'test.xcodeproj')66 project.new_target(:application, 'AppA', :ios)67 project.save68 run_command('init')69 dependencies = config.podfile.target_definitions['AppA'].dependencies70 dependencies.map(&:name).should == ['AFNetworking']71 end72 end73 it 'handles hooking up mulitple test targets based on an xcodeproj project' do74 Dir.chdir(temporary_directory) do75 project = Xcodeproj::Project.new(temporary_directory + 'test.xcodeproj')76 project.new_target(:application, 'App', :ios)77 project.new_target(:unit_test_bundle, 'AppTests', :ios)78 project.new_target(:ui_test_bundle, 'AppFeatureTests', :ios)79 project.new_target(:application, 'Swifty App', :osx, nil, nil, :swift)80 project.save81 run_command('init')82 expected_podfile = <<-RUBY.strip_heredoc83 # Uncomment the next line to define a global platform for your project84 # platform :ios, '9.0'85 target 'App' do86 # Uncomment the next line if you're using Swift or would like to use dynamic frameworks87 # use_frameworks!88 # Pods for App89 target 'AppFeatureTests' do90 inherit! :search_paths91 # Pods for testing92 end93 target 'AppTests' do94 inherit! :search_paths95 # Pods for testing96 end97 end98 target 'Swifty App' do99 # Comment the next line if you're not using Swift and don't want to use dynamic frameworks100 use_frameworks!101 # Pods for Swifty App102 end103 RUBY104 File.read('Podfile').should == expected_podfile105 end106 end107 it 'includes default test pods in test targets in a Podfile' do108 Dir.chdir(temporary_directory) do109 tmp_templates_dir = Pathname.pwd + 'templates_dir'110 tmp_templates_dir.mkpath111 config.stubs(:templates_dir).returns(tmp_templates_dir)112 open(config.default_test_podfile_path, 'w') { |f| f << "pod 'Kiwi'" }113 project = Xcodeproj::Project.new(temporary_directory + 'test.xcodeproj')114 project.new_target(:application, 'App', :ios)115 project.new_target(:unit_test_bundle, 'AppTests', :ios)116 project.save117 run_command('init')118 dependencies = config.podfile.target_definitions['AppTests'].dependencies119 dependencies.map(&:name).should == ['Kiwi']120 end121 end122 it 'does not treat non-test targets as test targets' do123 Dir.chdir(temporary_directory) do124 tmp_templates_dir = Pathname.pwd + 'templates_dir'125 tmp_templates_dir.mkpath126 config.stubs(:templates_dir).returns(tmp_templates_dir)127 open(config.default_test_podfile_path, 'w') { |f| f << "pod 'Kiwi'" }128 project = Xcodeproj::Project.new(temporary_directory + 'test.xcodeproj')129 project.new_target(:application, 'Test', :ios)130 project.new_target(:application, 'Test Test Test', :ios)131 project.save132 run_command('init')133 config.podfile.target_definitions['Test'].dependencies.should.be.empty134 config.podfile.target_definitions['Test Test Test'].dependencies.should.be.empty135 end136 end137 it 'does not include default test pods if there are no test targets' do138 Dir.chdir(temporary_directory) do139 tmp_templates_dir = Pathname.pwd + 'templates_dir'140 tmp_templates_dir.mkpath141 config.stubs(:templates_dir).returns(tmp_templates_dir)142 open(config.default_test_podfile_path, 'w') { |f| f << "pod 'Kiwi'" }143 project = Xcodeproj::Project.new(temporary_directory + 'test.xcodeproj')144 project.new_target(:application, 'App', :ios)145 project.save146 run_command('init')147 config.podfile.nil?.should == false148 config.podfile.dependencies.length.should == 0149 end150 end151 it 'saves xcode project file in Podfile if one was supplied' do152 Dir.chdir(temporary_directory) do153 Xcodeproj::Project.new(temporary_directory + 'test1.xcodeproj').save154 Xcodeproj::Project.new(temporary_directory + 'Project.xcodeproj').save155 run_command('init', 'Project.xcodeproj')156 target_definition = config.podfile.target_definitions.values.first157 target_definition.user_project_path.should == 'Project.xcodeproj'158 end159 end160 it "doesn't save xcode project file in Podfile if one wasn't supplied" do161 Dir.chdir(temporary_directory) do162 Xcodeproj::Project.new(temporary_directory + 'Project.xcodeproj').save163 run_command('init')164 target_definition = config.podfile.target_definitions.values.first165 target_definition.user_project_path.should.nil?166 end167 end168 end169end...
project_setup.rb
Source:project_setup.rb
...25 # ----------------------------------------------------------------------26 # Add new packages27 # ----------------------------------------------------------------------28 def add_entity_framework29 builder.run_command('dotnet add package Microsoft.EntityFrameworkCore.Design')30 builder.run_command('dotnet add package Microsoft.EntityFrameworkCore.Tools')31 end32 def add_sql_server33 add_entity_framework34 if project_flag.use_sql_server35 builder.run_command('dotnet add package Microsoft.EntityFrameworkCore.SqlServer')36 else37 log.error('Cannot add SQL Server package while project_flag.use_sql_server is false')38 end39 end40 def add_pgsql41 add_entity_framework42 if project_flag.use_pgsql43 builder.run_command('dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL')44 builder.run_command('dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL.Design')45 else46 log.error('Cannot add PostgreSQL package while project_flag.use_pgsql is false')47 end48 end49 def add_serilog50 builder.run_command('dotnet add package Serilog')51 builder.run_command('dotnet add package Serilog.Sinks.Console')52 builder.run_command('dotnet add package Serilog.Sinks.Console')53 builder.run_command('dotnet add package Serilog.Enrichers.Environment')54 # builder.run_command('dotnet add package Serilog.Sinks.File')55 end56 def initialize_secret57 builder.run_command('dotnet user-secrets init')58 # dotnet user-secrets set "Db:Password" "12345"59 end60 def cop61 # Manually add this to project, todo: Support XML file updates so this can be automated62 # <CodeAnalysisRuleSet>StyleCop.ruleset</CodeAnalysisRuleSet>63 builder64 .add_file('StyleCop.ruleset', template_file: 'StyleCop.ruleset')65 .run_command('dotnet add package StyleCop.Analyzers')66 # Going to need to use NokiGori to do this67 # <CodeAnalysisRuleSet>StyleCop.ruleset</CodeAnalysisRuleSet>68 # csproj = File.expand_path(File.join(project.app_path, "#{project.application}.csproj"))69 # if File.exist?(csproj)70 # content = File.read(csproj)71 # end72 end73end...
run_command
Using AI Code Generation
1project1 = Project.new('Project ABC', 'I am a project', 'John Doe')2puts project1.add_to_team('Jane Doe')3puts project1.add_to_team('Jane Doe')4puts project1.add_to_team('Jane Doe')5puts project1.add_to_team('Jane Doe')6puts project1.add_to_team('Jane Doe')7puts project1.add_to_team('Jane Doe')8puts project1.add_to_team('Jane Doe')9puts project1.add_to_team('Jane Doe')10puts project1.add_to_team('Jane Doe')11puts project1.add_to_team('Jane Doe')12puts project1.add_to_team('Jane Doe')13puts project1.add_to_team('Jane Doe')14puts project1.add_to_team('Jane Doe')15puts project1.add_to_team('Jane Doe')16puts project1.add_to_team('Jane Doe')17puts project1.add_to_team('Jane Doe')18puts project1.add_to_team('Jane Doe')19puts project1.add_to_team('Jane Doe')20puts project1.add_to_team('Jane Doe')21puts project1.add_to_team('Jane Doe')22puts project1.add_to_team('Jane Doe')23puts project1.add_to_team('Jane Doe')24puts project1.add_to_team('Jane Doe')25puts project1.add_to_team('Jane Doe')26puts project1.add_to_team('Jane Doe')27puts project1.add_to_team('Jane Doe')28puts project1.add_to_team('Jane Doe')29puts project1.add_to_team('Jane Doe')30puts project1.add_to_team('Jane Doe')31puts project1.add_to_team('Jane Doe')32puts project1.add_to_team('Jane Doe')33project1.add_to_team('Jane Doe')34project1.add_to_team('Jane Doe')35project1.add_to_team('Jane Doe')36project1.add_to_team('Jane Doe')37project1.add_to_team('Jane Doe')38project1.add_to_team('Jane Doe')39project1.add_to_team('Jane Doe')40project1.add_to_team('Jane Doe')41project1.add_to_team('Jane Doe')42project1.add_to_team('Jane Doe')43project1.add_to_team('Jane Doe')44project1.add_to_team('Jane Doe')45project1.add_to_team('Jane Doe')46project1.add_to_team('Jane Doe')47project1.add_to_team('Jane Doe')48project1.add_to_team('Jane Doe')49project1.add_to_team('Jane Doe')
run_command
Using AI Code Generation
1project1 = Project.new('Project ABC', 'I am a project', 'John Doe')2puts project1.add_to_team('Jane Doe')3puts project1.add_to_team('Jane Doe')4puts project1.add_to_team('Jane Doe')5puts project1.add_to_team('Jane Doe')6puts project1.add_to_team('Jane Doe')7puts project1.add_to_team('Jane Doe')8puts project1.add_to_team('Jane Doe')9puts project1.add_to_team('Jane Doe')10puts project1.add_to_team('Jane Doe')11puts project1.add_to_team('Jane Doe')12puts project1.add_to_team('Jane Doe')13puts project1.add_to_team('Jane Doe')14puts project1.add_to_team('Jane Doe')15puts project1.add_to_team('Jane Doe')16puts project1.add_to_team('Jane Doe')17puts project1.add_to_team('Jane Doe')18puts project1.add_to_team('Jane Doe')19puts project1.add_to_team('Jane Doe')20puts project1.add_to_team('Jane Doe')21puts project1.add_to_team('Jane Doe')22puts project1.add_to_team('Jane Doe')23puts project1.add_to_team('Jane Doe')24puts project1.add_to_team('Jane Doe')25puts project1.add_to_team('Jane Doe')26puts project1.add_to_team('Jane Doe')27puts project1.add_to_team('Jane Doe')28puts project1.add_to_team('Jane Doe')29puts project1.add_to_team('Jane Doe')30puts project1.add_to_team('Jane Doe')31puts project1.add_to_team('Jane Doe')32puts project1.add_to_team('Jane Doe')33project1.add_to_team('Jane Doe')34project1.add_to_team('Jane Doe')_), '__), 'my_file')
run_command
Using AI Code Generation
1p.run_command('ls -l')2 def run_command(cmd)3p.run_command('ls -l')4NameError (uninitialized constant Project):5 @user = User.find(params[:id])6 @user.update(user_params)7 post.update(user_id: @user.id)8 @user = User.find(params[:id])9 @user.update(user_params)10 post.update(user_id: @user.id)11File.open('test.txt', 'r') do |f|
run_command
Using AI Code Generation
1 def run_command(command)2 system(command)3system(commandf4 def run_command(command)5 system(command)6 def run_command(command)
run_command
Using AI Code Generation
1 def run_command(command)2 system(command)3system(command)4 def run_command(command)5 system(command)6 def run_comand(command)
run_command
Using AI Code Generation
1project = Project.new("Project ABC")2project.add_to_team("John Smith")3project.add_to_team("Jane Smith")4 de initaize(name, description="description")5 def add_to_team(member)6 @team.each { |member| puts member }7 before(:each) do8 @project1 = Project.new('Project 1', 'description 19 expect(@project1.name).to eq("Changed Name")10 expect(@project1.description).to eq("Changed description")11 expect(@project1.elevator_pitch).to eq("Project 1, description 1")12 @project1.add_to_team("John Smith")13 expect(@project1.team).to eq(["John Smith"])14 @project1.add_to_team("John Smith")15 @project1.add_to_team("Jane Smith")16 expect(@project1.print_team).to eq("Team:17project1.add_to_team('Jane Doe')18project1.add_to_team('Jane Doe')19project1.add_to_team('Jane Doe')20project1.add_to_team('Jane Doe')21project1.add_to_team('Jane Doe')22project1.add_to_team('Jane Doe')23project1.add_to_team('Jane Doe')24project1.add_to_team('Jane Doe')25project1.add_to_team('Jane Doe')26project1.add_to_team('Jane Doe')27project1.add_to_team('Jane Doe')28project1.add_to_team('Jane Doe')29project1.add_to_team('Jane Doe')30project1.add_to_team('Jane Doe')31project1.add_to_team('Jane Doe')
run_command
Using AI Code Generation
1project = Project.new("Project ABC")2project.add_to_team("John Smith")3project.add_to_team("Jane Smith")4 def initialize(name, description="description")5 def add_to_team(member)6 @team.each { |member| puts member }7 before(:each) do8 @project1 = Project.new('Project 1', 'description 1')9 expect(@project1.name).to eq("Changed Name")10 expect(@project1.description).to eq("Changed description")11 expect(@project1.elevator_pitch).to eq("Project 1, description 1")12 @project1.add_to_team("John Smith")13 expect(@project1.team).to eq(["John Smith"])14 @project1.add_to_team("John Smith")15 @project1.add_to_team("Jane Smith")16 expect(@project1.print_team).to eq("Team:
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!