Sha256: 0a2d621e9bba13cacd9711d365a3162a4846f1c70fed5e1b9b3338563f32d9ee

Contents?: true

Size: 1.41 KB

Versions: 19

Compression:

Stored size: 1.41 KB

Contents

require File.dirname(__FILE__) + '/../../spec_helper'

describe "AssignsHashProxy" do
  before(:each) do
    @object = Object.new
    @assigns = Hash.new
    @object.stub!(:assigns).and_return(@assigns)
    @proxy = Spec::Rails::Example::AssignsHashProxy.new(@object)
  end

  it "has [] accessor" do
    @proxy['foo'] = 'bar'
    @assigns['foo'].should == 'bar'
    @proxy['foo'].should == 'bar'
  end

  it "works for symbol key" do
    @assigns[:foo] = 2
    @proxy[:foo].should == 2
  end

  it "checks for string key before symbol key" do
    @assigns['foo'] = false
    @assigns[:foo] = 2
    @proxy[:foo].should == false
  end

  it "each method iterates through each element like a Hash" do
    values = {
      'foo' => 1,
      'bar' => 2,
      'baz' => 3
    }
    @proxy['foo'] = values['foo']
    @proxy['bar'] = values['bar']
    @proxy['baz'] = values['baz']

    @proxy.each do |key, value|
      key.should == key
      value.should == values[key]
    end
  end

  it "delete method deletes the element of passed in key" do
    @proxy['foo'] = 'bar'
    @proxy.delete('foo').should == 'bar'
    @proxy['foo'].should be_nil
  end

  it "has_key? detects the presence of a key" do
    @proxy['foo'] = 'bar'
    @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

Version data entries

19 entries across 19 versions & 4 rubygems

Version Path
jcnetdev-rspec-rails-1.1.5 spec/rails/example/assigns_hash_proxy_spec.rb
jstorimer-deep-test-2.0.0 sample_rails_project/vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
jstorimer-deep-test-1.4.0 sample_rails_project/vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
jstorimer-deep-test-1.3.0 sample_rails_project/vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
jstorimer-deep-test-1.2.0 sample_rails_project/vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
jstorimer-deep-test-1.1.0 sample_rails_project/vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
jstorimer-deep-test-1.0.0 sample_rails_project/vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
jstorimer-deep-test-0.2.0 sample_rails_project/vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
jstorimer-deep-test-0.1.0 sample_rails_project/vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
radiant-0.6.5.1 vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
radiant-0.6.5 vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
radiant-0.6.7 vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
radiant-0.6.6 vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
radiant-0.6.9 vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
radiant-0.6.8 vendor/plugins/rspec_on_rails/spec/rails/example/assigns_hash_proxy_spec.rb
spree-0.4.1 vendor/plugins/rspec-rails/spec/rails/example/assigns_hash_proxy_spec.rb
spree-0.4.0 vendor/plugins/rspec-rails/spec/rails/example/assigns_hash_proxy_spec.rb
spree-0.5.0 vendor/plugins/rspec-rails/spec/rails/example/assigns_hash_proxy_spec.rb
spree-0.5.1 vendor/plugins/rspec-rails/spec/rails/example/assigns_hash_proxy_spec.rb