changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/extensions/main_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
3module Spec
4 module Extensions
5 describe Main do
6 it_should_behave_like "sandboxed rspec_options"
7 before(:each) do
8 @main = Class.new do; include Main; end
9 end
10
11 after(:each) do
12 $rspec_story_steps = @original_rspec_story_steps
13 end
14
15 it "should create an Options object" do
16 @main.send(:rspec_options).should be_instance_of(Spec::Runner::Options)
17 @main.send(:rspec_options).should === $rspec_options
18 end
19
20 specify {@main.should respond_to(:describe)}
21 specify {@main.should respond_to(:context)}
22
23 it "should raise when no block given to describe" do
24 lambda { @main.describe "foo" }.should raise_error(ArgumentError)
25 end
26
27 it "should raise when no description given to describe" do
28 lambda { @main.describe do; end }.should raise_error(ArgumentError)
29 end
30
31 it "should registered ExampleGroups by default" do
32 example_group = @main.describe("The ExampleGroup") do end
33 rspec_options.example_groups.should include(example_group)
34 end
35
36 it "should not run unregistered ExampleGroups" do
37 example_group = @main.describe("The ExampleGroup") do
38 unregister
39 end
40
41 rspec_options.example_groups.should_not include(example_group)
42 end
43
44 it "should create a shared ExampleGroup with share_examples_for" do
45 group = @main.share_examples_for "all things" do end
46 group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
47 end
48
49 describe "#share_as" do
50 before(:each) do
51 $share_as_examples_example_module_number ||= 1
52 $share_as_examples_example_module_number += 1
53 t = Time.new.to_i
54 @group_name = "Group#{$share_as_examples_example_module_number}"
55 end
56
57 it "should create a shared ExampleGroup" do
58 group = @main.share_as @group_name do end
59 group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
60 end
61
62 it "should create a constant that points to a Module" do
63 group = @main.share_as @group_name do end
64 Object.const_get(@group_name).should equal(group)
65 end
66
67 it "should bark if you pass it something not-constantizable" do
68 lambda do
69 @group = @main.share_as "Non Constant" do end
70 end.should raise_error(NameError, /The first argument to share_as must be a legal name for a constant/)
71 end
72
73 end
74 end
75 end
76end