require 'spec_helper' describe PrimeTable, 'prompt' do before do @optimus = PrimeTable::Optimus.new IO.any_instance.stub(:puts) end it "should return if quitted" do @optimus.parse_input('q').should be_nil end it "should act as 10 if nothing given" do end describe "when given stuff" do # before { @optimus.parse_input('0') } it "should give generic response to 0/1/non-number" do # SpecHelper.local_io.should == "Orly? Here you go! []" end end context Calculate do it "should get primes correctly" do Calculate.n_primes(10).should have(10).items end it "should get next prime given number" do Calculate.next_prime(168).should equal(173) end it "should report primes correctly" do Calculate.is_prime?(3).should be_true Calculate.is_prime?(30).should be_false Calculate.is_prime?(173).should be_true end end context Display do it "should display table well" do # primes = [2,3,5,7] # Display.table(primes).should_receive(:stdout).with """ # 2 | 3 | 5 | 7 | # ---- |---- |---- |---- | # 2 - 4 | 6 | 10 | 14 | # 3 - 6 | 9 | 15 | 21 | # 5 - 10 | 15 | 25 | 35 | # 7 - 14 | 21 | 35 | 49 | # """ end it "should give formatted strings for display" do expect(Display.for_primes(1, 5)).to eq "%5d |" expect(Display.for_primes(2, 5)).to eq "%5d |%5d |" end end end