spec/specs.rb in opal-spec-0.2.10 vs spec/specs.rb in opal-spec-0.2.11

- old
+ new

@@ -1,34 +1,27 @@ -@passed = 0 -@failures = [] +describe 'Normal group' do + it 'exceptions can be thrown' do + err = nil -def assert(value, message='Not true') - if value - @passed += 1 - else - @failures << message - end -end + begin + 1.should == 2 + rescue => e + err = e + end -def assert_equal(got, expected, message='Not equal') - assert(got == expected, message) -end - -describe 'Normal group' do - it 'this should fail' do - 1.should == 2 + raise "exception not thrown" unless err end end describe "New eql" do it "these should both pass" do 1.should eq(1) 1.should_not eq(2) end it "and this should fail" do - 1.should eq(:adam) + lambda { 1.should eq(:adam) }.should raise_error(Exception) end end describe Object do it "should output a nice name for classes" do @@ -39,14 +32,10 @@ describe 'Another group' do it 'this should pass' do 1.should == 1 end - it 'this should fail' do - raise "whatever error you like" - end - it 'this should pass' do true.should be_true false.should be_false nil.should be_nil end @@ -60,14 +49,43 @@ end async 'this should fail (in 0.1 second time)' do set_timeout(100) do run_async { - 1.should == 5 + lambda { 1.should == 5 }.should raise_error(Exception) } end end end -Opal::Spec::Runner.autorun +describe "let" do + $opal_spec_let_count = 0 -puts "Assertions: #{@passed + @failures.length}, Passed: #{@passed}, Failures: #{@failures.length}" + let(:count) { $opal_spec_let_count = $opal_spec_let_count + 1 } + + it "caches the method for the example" do + count.should eq(1) + count.should eq(1) + end + + it "does not cache values between different examples" do + count.should eq(2) + end +end + +describe "before" do + before do + @foo = 100 + end + + before do + @bar = 200 + end + + it "should be run before each group" do + @foo.should == 100 + end + + it "should run multiple before blocks" do + @bar.should == 200 + end +end