diff options
author | francis <francis> | 2008-09-04 06:10:25 +0000 |
---|---|---|
committer | francis <francis> | 2008-09-04 06:10:25 +0000 |
commit | 5bde1025dc4d43ea53f63107b88711ebf8942408 (patch) | |
tree | 962c8b1fb32186fbd1ab15050ede8e560d9a63f6 /vendor/plugins/rspec_on_rails/spec | |
parent | ce2cf5ed73d81180e9f88d590daaa23989ee9472 (diff) |
rspec for rails 2.1
Diffstat (limited to 'vendor/plugins/rspec_on_rails/spec')
16 files changed, 462 insertions, 103 deletions
diff --git a/vendor/plugins/rspec_on_rails/spec/rails/autotest/mappings_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/autotest/mappings_spec.rb index 7a2658d2c..3ebf8909a 100644 --- a/vendor/plugins/rspec_on_rails/spec/rails/autotest/mappings_spec.rb +++ b/vendor/plugins/rspec_on_rails/spec/rails/autotest/mappings_spec.rb @@ -1,41 +1,36 @@ require File.dirname(__FILE__) + '/../../spec_helper' -require File.join(File.dirname(__FILE__), "..", "..", "..", "lib", "autotest", "rails_rspec") +require File.join(File.dirname(__FILE__), *%w[.. .. .. lib autotest rails_rspec]) +require File.join(File.dirname(__FILE__), *%w[.. .. .. .. rspec spec autotest_matchers]) describe Autotest::RailsRspec, "file mapping" do before(:each) do @autotest = Autotest::RailsRspec.new @autotest.hook :initialize - @autotest.output = StringIO.new - @autotest.files.clear - @autotest.last_mtime = Time.at(0) - end - - def ensure_mapping(examples, impl) - @autotest.files[@impl] = Time.at(0) - examples.each do |example| - @autotest.files[example] = Time.at(0) - end - @autotest.tests_for_file(impl).should == examples end it "should map model example to model" do - ensure_mapping(['spec/models/thing_spec.rb'], 'app/models/thing.rb') + @autotest.should map_specs(['spec/models/thing_spec.rb']). + to('app/models/thing.rb') end it "should map controller example to controller" do - ensure_mapping(['spec/controllers/things_controller_spec.rb'], 'app/controllers/things_controller.rb') + @autotest.should map_specs(['spec/controllers/things_controller_spec.rb']). + to('app/controllers/things_controller.rb') end it "should map view.rhtml" do - ensure_mapping(['spec/views/things/index.rhtml_spec.rb'], 'app/views/things/index.rhtml') + @autotest.should map_specs(['spec/views/things/index.rhtml_spec.rb']). + to('app/views/things/index.rhtml') end it "should map view.rhtml with underscores in example filename" do - ensure_mapping(['spec/views/things/index_rhtml_spec.rb'], 'app/views/things/index.rhtml') + @autotest.should map_specs(['spec/views/things/index_rhtml_spec.rb']). + to('app/views/things/index.rhtml') end it "should map view.html.erb" do - ensure_mapping(['spec/views/things/index.html.erb_spec.rb'], 'app/views/things/index.html.erb') + @autotest.should map_specs(['spec/views/things/index.html.erb_spec.rb']). + to('app/views/things/index.html.erb') end end diff --git a/vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb index 400fb829d..eab67f696 100644 --- a/vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb +++ b/vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb @@ -1,6 +1,6 @@ require File.dirname(__FILE__) + '/../../spec_helper' -describe "An AssignsHashProxy" do +describe "AssignsHashProxy" do before(:each) do @object = Object.new @assigns = Hash.new @@ -52,4 +52,9 @@ describe "An AssignsHashProxy" do @proxy.has_key?('foo').should == true @proxy.has_key?('bar').should == false end + + it "should sets an instance var" do + @proxy['foo'] = 'bar' + @object.instance_eval { @foo }.should == 'bar' + end end diff --git a/vendor/plugins/rspec_on_rails/spec/rails/example/controller_isolation_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/example/controller_isolation_spec.rb index 204db15d6..9e40047aa 100644 --- a/vendor/plugins/rspec_on_rails/spec/rails/example/controller_isolation_spec.rb +++ b/vendor/plugins/rspec_on_rails/spec/rails/example/controller_isolation_spec.rb @@ -32,7 +32,8 @@ describe "a controller spec running in integration mode", :type => :controller d end it "should choke if the template doesn't exist" do - lambda { get 'some_action' }.should raise_error(ActionController::MissingTemplate) + error = defined?(ActionController::MissingTemplate) ? ActionController::MissingTemplate : ActionView::MissingTemplate + lambda { get 'some_action' }.should raise_error(error) response.should_not be_success end @@ -40,4 +41,22 @@ describe "a controller spec running in integration mode", :type => :controller d lambda { get 'action_with_errors_in_template' }.should raise_error(ActionView::TemplateError) response.should_not be_success end + + describe "nested" do + it "should render a template" do + get 'action_with_template' + response.should be_success + response.should have_tag('div', 'This is action_with_template.rhtml') + end + + describe "with integrate_views turned off" do + integrate_views false + + it "should not care if the template doesn't exist" do + get 'some_action' + response.should be_success + response.should render_template("template/that/does/not/actually/exist") + end + end + end end diff --git a/vendor/plugins/rspec_on_rails/spec/rails/example/controller_spec_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/example/controller_spec_spec.rb index 3cc861d83..afbb69f7a 100644 --- a/vendor/plugins/rspec_on_rails/spec/rails/example/controller_spec_spec.rb +++ b/vendor/plugins/rspec_on_rails/spec/rails/example/controller_spec_spec.rb @@ -17,6 +17,12 @@ require 'controller_spec_controller' session.should equal(session_before) end + it "should keep the same data in the session before and after the action" do + session[:foo] = :bar + get 'action_with_template' + session[:foo].should == :bar + end + it "should ensure controller.session is NOT nil before the action" do controller.session.should_not be_nil get 'action_with_template' @@ -47,13 +53,20 @@ require 'controller_spec_controller' get 'action_with_partial_with_locals', :thing => "something" end + it "should yield to render :update" do + template = stub("template") + controller.expect_render(:update).and_yield(template) + template.should_receive(:replace).with(:bottom, "replace_me", :partial => "non_existent_partial") + get 'action_with_render_update' + end + it "should allow a path relative to RAILS_ROOT/app/views/ when specifying a partial" do get 'action_with_partial' response.should render_template("controller_spec/_partial") end it "should provide access to flash" do - get 'action_with_template' + get 'action_which_sets_flash' flash[:flash_key].should == "flash value" end @@ -68,8 +81,10 @@ require 'controller_spec_controller' end it "should provide access to session" do - get 'action_with_template' - session[:session_key].should == "session value" + session[:session_key] = "session value" + lambda do + get 'action_which_gets_session', :expected => "session value" + end.should_not raise_error end it "should support custom routes" do @@ -105,6 +120,7 @@ require 'controller_spec_controller' end it "should complain when calling stub!(:render) on the controller" do + controller.extend Spec::Mocks::Methods lambda { controller.stub!(:render) }.should raise_error(RuntimeError, /stub!\(:render\) has been disabled/) @@ -161,6 +177,17 @@ describe ControllerSpecController, :type => :controller do end end +describe "A controller spec with controller_name set", :type => :controller do + controller_name :controller_spec + + describe "nested" do + it "should inherit the controller name" do + get 'action_with_template' + response.should be_success + end + end +end + module Spec module Rails module Example diff --git a/vendor/plugins/rspec_on_rails/spec/rails/example/helper_spec_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/example/helper_spec_spec.rb index 50defecc5..0ba2cd255 100644 --- a/vendor/plugins/rspec_on_rails/spec/rails/example/helper_spec_spec.rb +++ b/vendor/plugins/rspec_on_rails/spec/rails/example/helper_spec_spec.rb @@ -2,8 +2,11 @@ require File.dirname(__FILE__) + '/../../spec_helper' Spec::Runner.configuration.global_fixtures = :people describe ExplicitHelper, :type => :helper do + include ExplicitHelper + it "should not require naming the helper if describe is passed a type" do method_in_explicit_helper.should match(/text from a method/) + helper.method_in_explicit_helper.should match(/text from a method/) end end @@ -13,17 +16,22 @@ module Spec describe HelperExampleGroup, :type => :helper do helper_name :explicit - it "should have direct access to methods defined in helpers" do + it "DEPRECATED should have direct access to methods defined in helpers" do method_in_explicit_helper.should =~ /text from a method/ end + it "should expose the helper with the #helper method" do + helper.method_in_explicit_helper.should =~ /text from a method/ + end + it "should have access to named routes" do rspec_on_rails_specs_url.should == "http://test.host/rspec_on_rails_specs" rspec_on_rails_specs_path.should == "/rspec_on_rails_specs" end it "should fail if the helper method deson't exist" do - lambda { non_existant_helper_method }.should raise_error(NameError) + lambda { non_existent_helper_method }.should raise_error(NameError) + lambda { helper.non_existent_helper_method }.should raise_error(NameError) end end @@ -50,6 +58,13 @@ module Spec lachie.class.should == Person end end + + describe "methods from standard helpers", :type => :helper do + helper_name :explicit + it "should be exposed to the helper" do + helper.link_to("Foo","http://bar").should have_tag("a") + end + end describe HelperExampleGroup, "included modules", :type => :helper do helpers = [ @@ -74,9 +89,10 @@ module Spec helpers << ActionView::Helpers::PaginationHelper rescue nil #removed for 2.0 helpers << ActionView::Helpers::JavaScriptMacrosHelper rescue nil #removed for 2.0 helpers.each do |helper_module| - it "should include #{helper_module}" do - self.class.ancestors.should include(helper_module) - end + # it "should include #{helper_module}" do + # self.class.ancestors.should include(helper_module) + # helper.class.ancestors.should include(helper_module) + # end end end @@ -85,6 +101,7 @@ module Spec describe HelperExampleGroup, "#protect_against_forgery?", :type => :helper do it "should return false" do protect_against_forgery?.should be_false + helper.protect_against_forgery?.should be_false end end end diff --git a/vendor/plugins/rspec_on_rails/spec/rails/example/view_spec_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/example/view_spec_spec.rb index 17e47eee8..14159c65a 100644 --- a/vendor/plugins/rspec_on_rails/spec/rails/example/view_spec_spec.rb +++ b/vendor/plugins/rspec_on_rails/spec/rails/example/view_spec_spec.rb @@ -208,6 +208,14 @@ describe "A view", :type => :view do it "should have access to flash data" do response.should have_tag("div#flash", "flash") end + + it "should have a controller param" do + response.should have_tag("div#controller", "view_spec") + end + + it "should have an action param" do + response.should have_tag("div#action", "accessor") + end end describe "A view with a form_tag", :type => :view do @@ -231,6 +239,13 @@ describe "An instantiated ViewExampleGroupController", :type => :view do end end +describe "render :inline => ...", :type => :view do + it "should render ERB right in the spec" do + render :inline => %|<%= text_field_tag('field_name', 'Value') %>| + response.should have_tag("input[type=?][name=?][value=?]","text","field_name","Value") + end +end + module Spec module Rails module Example @@ -243,7 +258,15 @@ module Spec group.description.to_s.should == "foo" $nested_group.description.to_s.should == "foo bar" end + + it "should clear ActionView::Base.base_view_path on teardown" do + group = describe("base_view_path_cleared flag", :type => :view) {} + example = group.it{} + + ActionView::Base.should_receive(:base_view_path=).with(nil) + group.run_after_each(example) + end end end end -end
\ No newline at end of file +end diff --git a/vendor/plugins/rspec_on_rails/spec/rails/extensions/action_view_base_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/extensions/action_view_base_spec.rb index 9d3e759b2..599249f06 100644 --- a/vendor/plugins/rspec_on_rails/spec/rails/extensions/action_view_base_spec.rb +++ b/vendor/plugins/rspec_on_rails/spec/rails/extensions/action_view_base_spec.rb @@ -1,37 +1,48 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'spec/mocks/errors' -describe ActionView::Base, "with RSpec extensions", :type => :view do - it "should not raise when render has been received" do - template.expect_render(:partial => "name") - template.render :partial => "name" - end +describe ActionView::Base, "with RSpec extensions:", :type => :view do - it "should raise when render has NOT been received" do - template.expect_render(:partial => "name") - lambda { - template.verify_rendered - }.should raise_error - end + describe "expect_render" do + it "should not raise when render has been received" do + template.expect_render(:partial => "name") + template.render :partial => "name" + end - it "should not raise when stubbing and render has been received" do - template.stub_render(:partial => "name") - template.render :partial => "name" + it "should raise when render has NOT been received" do + template.expect_render(:partial => "name") + lambda { + template.verify_rendered + }.should raise_error + end + + it "should return something (like a normal mock)" do + template.expect_render(:partial => "name").and_return("Little Johnny") + result = template.render :partial => "name" + result.should == "Little Johnny" + end end - it "should not raise when stubbing and render has NOT been received" do - template.stub_render(:partial => "name") - end + describe "stub_render" do + it "should not raise when stubbing and render has been received" do + template.stub_render(:partial => "name") + template.render :partial => "name" + end - it "should not raise when stubbing and render has been received with different options" do - template.stub_render(:partial => "name") - template.render :partial => "view_spec/spacer" - end + it "should not raise when stubbing and render has NOT been received" do + template.stub_render(:partial => "name") + end + + it "should not raise when stubbing and render has been received with different options" do + template.stub_render(:partial => "name") + template.render :partial => "view_spec/spacer" + end - it "should not raise when stubbing and expecting and render has been received" do - template.stub_render(:partial => "name") - template.expect_render(:partial => "name") - template.render(:partial => "name") + it "should not raise when stubbing and expecting and render has been received" do + template.stub_render(:partial => "name") + template.expect_render(:partial => "name") + template.render(:partial => "name") + end end - + end diff --git a/vendor/plugins/rspec_on_rails/spec/rails/matchers/include_text_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/matchers/include_text_spec.rb new file mode 100644 index 000000000..1ac3fd7c6 --- /dev/null +++ b/vendor/plugins/rspec_on_rails/spec/rails/matchers/include_text_spec.rb @@ -0,0 +1,70 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe "include_text" do + + describe "where target is a String" do + it 'should match submitted text using a string' do + string = 'foo' + string.should include_text('foo') + end + + it 'should match if the text is contained' do + string = 'I am a big piece of text' + string.should include_text('big piece') + end + + it 'should not match if text is not contained' do + string = 'I am a big piece of text' + string.should_not include_text('corey') + end + end + +end + +describe "include_text", :type => :controller do + ['isolation','integration'].each do |mode| + if mode == 'integration' + integrate_views + end + + describe "where target is a response (in #{mode} mode)" do + controller_name :render_spec + + it "should pass with exactly matching text" do + post 'text_action' + response.should include_text("this is the text for this action") + end + + it 'should pass with substring matching text' do + post 'text_action' + response.should include_text('text for this') + end + + it "should fail with matching text" do + post 'text_action' + lambda { + response.should include_text("this is NOT the text for this action") + }.should fail_with("expected to find \"this is NOT the text for this action\" in \"this is the text for this action\"") + end + + it "should fail when a template is rendered" do + post 'some_action' + failure_message = case mode + when 'isolation' + /expected to find \"this is the text for this action\" in \"render_spec\/some_action\"/ + when 'integration' + /expected to find \"this is the text for this action\" in \"\"/ + end + lambda { + response.should include_text("this is the text for this action") + }.should fail_with(failure_message) + end + + it "should pass using should_not with incorrect text" do + post 'text_action' + response.should_not include_text("the accordian guy") + end + end + end +end + diff --git a/vendor/plugins/rspec_on_rails/spec/rails/matchers/redirect_to_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/matchers/redirect_to_spec.rb index b3c7d7a86..e3ce486d4 100644 --- a/vendor/plugins/rspec_on_rails/spec/rails/matchers/redirect_to_spec.rb +++ b/vendor/plugins/rspec_on_rails/spec/rails/matchers/redirect_to_spec.rb @@ -21,6 +21,12 @@ require File.dirname(__FILE__) + '/../../spec_helper' get 'action_with_redirect_to_somewhere_and_return' response.should redirect_to(:action => 'somewhere') end + + it "redirected from an SSL action to a non-SSL action" do + request.stub!(:ssl?).and_return true + get 'action_with_redirect_to_somewhere' + response.should redirect_to(:action => 'somewhere') + end it "redirected to correct path with leading /" do get 'action_with_redirect_to_somewhere' diff --git a/vendor/plugins/rspec_on_rails/spec/rails/matchers/render_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/matchers/render_spec.rb index 5dbf576f1..93cca867f 100644 --- a/vendor/plugins/rspec_on_rails/spec/rails/matchers/render_spec.rb +++ b/vendor/plugins/rspec_on_rails/spec/rails/matchers/render_spec.rb @@ -30,11 +30,10 @@ require File.dirname(__FILE__) + '/../../spec_helper' it "should match an rjs template" do xhr :post, 'some_action' - if ActionView::Base.const_defined?('DEFAULT_TEMPLATE_HANDLER_PREFERENCE') || - ActionView::Base.respond_to?(:handler_for_extension) then - response.should render_template('render_spec/some_action') - else + if Rails::VERSION::STRING < "2.0.0" response.should render_template('render_spec/some_action.rjs') + else + response.should render_template('render_spec/some_action') end end @@ -83,4 +82,88 @@ require File.dirname(__FILE__) + '/../../spec_helper' end.should fail_with("expected \"some_action\", got nil") end end + + describe "response.should_not render_template (in #{mode} mode)", + :type => :controller do + controller_name :render_spec + if mode == 'integration' + integrate_views + end + + it "should pass when the action renders nothing" do + post 'action_that_renders_nothing' + response.should_not render_template('action_that_renders_nothing') + end + + it "should pass when the action renders nothing (symbol)" do + post 'action_that_renders_nothing' + response.should_not render_template(:action_that_renders_nothing) + end + + it "should pass when the action does not render the template" do + post 'some_action' + response.should_not render_template('some_other_template') + end + + it "should pass when the action does not render the template (symbol)" do + post 'some_action' + response.should_not render_template(:some_other_template) + end + + it "should pass when the action does not render the template (named with controller)" do + post 'some_action' + response.should_not render_template('render_spec/some_other_template') + end + + it "should pass when the action renders the template with a different controller" do + post 'action_which_renders_template_from_other_controller' + response.should_not render_template('action_with_template') + end + + it "should pass when the action renders the template (named with controller) with a different controller" do + post 'action_which_renders_template_from_other_controller' + response.should_not render_template('render_spec/action_with_template') + end + + it "should pass when TEXT is rendered" do + post 'text_action' + response.should_not render_template('some_action') + end + + it "should fail when the action renders the template" do + post 'some_action' + lambda do + response.should_not render_template('some_action') + end.should fail_with("expected not to render \"some_action\", but did") + end + + it "should fail when the action renders the template (symbol)" do + post 'some_action' + lambda do + response.should_not render_template(:some_action) + end.should fail_with("expected not to render \"some_action\", but did") + end + + it "should fail when the action renders the template (named with controller)" do + post 'some_action' + lambda do + response.should_not render_template('render_spec/some_action') + end.should fail_with("expected not to render \"render_spec/some_action\", but did") + end + + it "should fail when the action renders the partial" do + post 'action_with_partial' + lambda do + response.should_not render_template('_a_partial') + end.should fail_with("expected not to render \"_a_partial\", but did") + end + + it "should fail when the action renders the partial (named with controller)" do + post 'action_with_partial' + lambda do + response.should_not render_template('render_spec/_a_partial') + end.should fail_with("expected not to render \"render_spec/_a_partial\", but did") + end + + end end diff --git a/vendor/plugins/rspec_on_rails/spec/rails/mocks/ar_classes.rb b/vendor/plugins/rspec_on_rails/spec/rails/mocks/ar_classes.rb new file mode 100644 index 000000000..05213029a --- /dev/null +++ b/vendor/plugins/rspec_on_rails/spec/rails/mocks/ar_classes.rb @@ -0,0 +1,10 @@ +class MockableModel < ActiveRecord::Base + has_one :associated_model +end + +class SubMockableModel < MockableModel +end + +class AssociatedModel < ActiveRecord::Base + belongs_to :mockable_model +end diff --git a/vendor/plugins/rspec_on_rails/spec/rails/mocks/mock_model_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/mocks/mock_model_spec.rb index 76793f0a1..9ca171b8e 100644 --- a/vendor/plugins/rspec_on_rails/spec/rails/mocks/mock_model_spec.rb +++ b/vendor/plugins/rspec_on_rails/spec/rails/mocks/mock_model_spec.rb @@ -1,17 +1,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' +require File.dirname(__FILE__) + '/ar_classes' -class MockableModel < ActiveRecord::Base - has_one :associated_model -end - -class SubMockableModel < MockableModel -end - -class AssociatedModel < ActiveRecord::Base - belongs_to :mockable_model -end - -describe "mock_model", :type => :view do +describe "mock_model" do before(:each) do @model = mock_model(SubMockableModel) end @@ -35,6 +25,15 @@ describe "mock_model", :type => :view do end end +describe "mock_model with stubbed id", :type => :view do + before(:each) do + @model = mock_model(MockableModel, :id => 1) + end + it "should be named using the stubbed id value" do + @model.instance_variable_get(:@name).should == "MockableModel_1" + end +end + describe "mock_model with null_object", :type => :view do before(:each) do @model = mock_model(MockableModel, :null_object => true, :mocked_method => "mocked") diff --git a/vendor/plugins/rspec_on_rails/spec/rails/mocks/stub_model_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/mocks/stub_model_spec.rb new file mode 100644 index 000000000..c123de009 --- /dev/null +++ b/vendor/plugins/rspec_on_rails/spec/rails/mocks/stub_model_spec.rb @@ -0,0 +1,78 @@ +require File.dirname(__FILE__) + '/../../spec_helper' +require File.dirname(__FILE__) + '/ar_classes' + +describe "stub_model" do + describe "defaults" do + it "should have an id" do + stub_model(MockableModel).id.should be > 0 + end + + it "should say it is not a new record" do + stub_model(MockableModel).should_not be_new_record + end + end + + it "should accept a stub id" do + stub_model(MockableModel, :id => 37).id.should == 37 + end + + it "should say it is a new record when id is set to nil" do + stub_model(MockableModel, :id => nil).should be_new_record + end + + it "should accept any arbitrary stub" do + stub_model(MockableModel, :foo => "bar").foo.should == "bar" + end + + it "should accept a stub for save" do + stub_model(MockableModel, :save => false).save.should be(false) + end + + describe "#as_new_record" do + it "should say it is a new record" do + stub_model(MockableModel).as_new_record.should be_new_record + end + + it "should have a nil id" do + stub_model(MockableModel).as_new_record.id.should be(nil) + end + end + + it "should raise when hitting the db" do + lambda do + stub_model(MockableModel).save + end.should raise_error(Spec::Rails::IllegalDataAccessException, /stubbed models are not allowed to access the database/) + end + + it "should increment the id" do + first = stub_model(MockableModel) + second = stub_model(MockableModel) + second.id.should == (first.id + 1) + end + +end + +describe "stub_model as association" do + before(:each) do + @real = AssociatedModel.create! + @stub_model = stub_model(MockableModel) + @real.mockable_model = @stub_model + end + + it "should pass associated_model == mock" do + @stub_model.should == @real.mockable_model + end + + it "should pass mock == associated_model" do + @real.mockable_model.should == @stub_model + end +end + +describe "stub_model with a block" do + it "should yield the model" do + model = stub_model(MockableModel) do |block_arg| + @block_arg = block_arg + end + model.should be(@block_arg) + end +end diff --git a/vendor/plugins/rspec_on_rails/spec/rails/sample_modified_fixture.rb b/vendor/plugins/rspec_on_rails/spec/rails/sample_modified_fixture.rb new file mode 100644 index 000000000..832049768 --- /dev/null +++ b/vendor/plugins/rspec_on_rails/spec/rails/sample_modified_fixture.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe "A sample spec", :type => :model do + fixtures :animals + it "should pass" do + animals(:pig).name.should == "Piggy" + end +end
\ No newline at end of file diff --git a/vendor/plugins/rspec_on_rails/spec/rails/sample_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/sample_spec.rb index 7cd1d4e81..a88e6070e 100644 --- a/vendor/plugins/rspec_on_rails/spec/rails/sample_spec.rb +++ b/vendor/plugins/rspec_on_rails/spec/rails/sample_spec.rb @@ -1,7 +1,8 @@ require File.dirname(__FILE__) + '/../spec_helper' -describe "A sample spec" do +describe "A sample spec", :type => :model do + fixtures :animals it "should pass" do - true.should === true + animals(:pig).name.should == "Pig" end end
\ No newline at end of file diff --git a/vendor/plugins/rspec_on_rails/spec/rails/spec_server_spec.rb b/vendor/plugins/rspec_on_rails/spec/rails/spec_server_spec.rb index 957bd1089..b70f10d90 100644 --- a/vendor/plugins/rspec_on_rails/spec/rails/spec_server_spec.rb +++ b/vendor/plugins/rspec_on_rails/spec/rails/spec_server_spec.rb @@ -2,12 +2,24 @@ require File.dirname(__FILE__) + '/../spec_helper' describe "script/spec_server file", :shared => true do attr_accessor :tmbundle_install_directory + attr_reader :animals_yml_path, :original_animals_content + + before do + @animals_yml_path = File.expand_path("#{RAILS_ROOT}/spec/fixtures/animals.yml") + @original_animals_content = File.read(animals_yml_path) + end after do - system "kill -9 #{@pid}" + File.open(animals_yml_path, "w") do |f| + f.write original_animals_content + end end - it "runs a spec" do + after(:each) do + system "lsof -i tcp:8989 | sed /COMMAND/d | awk '{print $2}' | xargs kill" + end + + xit "runs a spec" do dir = File.dirname(__FILE__) output = "" Timeout.timeout(10) do @@ -17,54 +29,49 @@ describe "script/spec_server file", :shared => true do end end - unless $?.exitstatus == 0 + if $?.exitstatus != 0 || output !~ /0 failures/ flunk "command 'script/spec spec/sample_spec' failed\n#{output}" end - end - def start_spec_server - create_spec_server_pid_file - start_spec_server_process - end + fixtures = YAML.load(@original_animals_content) + fixtures['pig']['name'] = "Piggy" + + File.open(animals_yml_path, "w") do |f| + f.write YAML.dump(fixtures) + end + + Timeout.timeout(10) do + loop do + output = `#{RAILS_ROOT}/script/spec #{dir}/sample_modified_fixture.rb --drb 2>&1` + break unless output.include?("No server is running") + end + end - def create_spec_server_pid_file - current_dir = File.dirname(__FILE__) - pid_dir = "#{Dir.tmpdir}/#{Time.now.to_i}" - @spec_server_pid_file = "#{pid_dir}/spec_server.pid" - FileUtils.mkdir_p pid_dir - system "touch #{@spec_server_pid_file}" - @rspec_path = File.expand_path("#{current_dir}/../../../rspec/lib") + if $?.exitstatus != 0 || output !~ /0 failures/ + flunk "command 'script/spec spec/sample_modified_fixture' failed\n#{output}" + end end - def start_spec_server_process + def start_spec_server dir = File.dirname(__FILE__) - spec_server_cmd = %Q|export HOME=#{Dir.tmpdir}; | - spec_server_cmd << %Q|ruby -e 'system("echo " + Process.pid.to_s + " > #{@spec_server_pid_file}"); | - spec_server_cmd << %Q|$LOAD_PATH.unshift("#{@rspec_path}"); require "spec"; | - spec_server_cmd << %Q|load "#{RAILS_ROOT}/script/spec_server"' &| - system spec_server_cmd + Thread.start do + system "cd #{RAILS_ROOT}; script/spec_server" + end file_content = "" - Timeout.timeout(5) do - loop do - file_content = File.read(@spec_server_pid_file) - break unless file_content.blank? - end - end - @pid = Integer(File.read(@spec_server_pid_file)) end end describe "script/spec_server file without TextMate bundle" do it_should_behave_like "script/spec_server file" - before do + before(:each) do start_spec_server end end describe "script/spec_server file with TextMate bundle" do it_should_behave_like "script/spec_server file" - before do + before(:each) do dir = File.dirname(__FILE__) @tmbundle_install_directory = File.expand_path("#{Dir.tmpdir}/Library/Application Support/TextMate/Bundles") @bundle_name = "RSpec.tmbundle" @@ -77,7 +84,7 @@ describe "script/spec_server file with TextMate bundle" do start_spec_server end - after do + after(:each) do bundle_file_to_remove = "#{tmbundle_install_directory}/#{@bundle_name}" if bundle_file_to_remove == "/" raise "bundle file path resolved to '/' - could not call rm" |