Re: [rspec-users] load global variable so I can access in spec files

2012-09-27 Thread S Ahmed
I do have it in my spec_helper, does it have to be inside the RSpec.config block? On Wed, Sep 26, 2012 at 11:17 PM, Andy Lindeman wrote: > On Wed, Sep 26, 2012 at 10:25 PM, S Ahmed wrote: > > How can I do this? > > If it's truly something that just needs to be loaded onc

Re: [rspec-users] How can I create a active-record model w/o depending on the database?

2012-09-23 Thread S Ahmed
n the dependancies of Myclass. On Sun, Sep 23, 2012 at 8:31 PM, David Chelimsky wrote: > On Sun, Sep 23, 2012 at 7:55 PM, S Ahmed wrote: > > I have a class that takes a class that inherits from activerecord as a > > parameter, e.g.: > > > > class SomeModel < ActiveRecord:

[rspec-users] How can I create a active-record model w/o depending on the database?

2012-09-23 Thread S Ahmed
I have a class that takes a class that inherits from activerecord as a parameter, e.g.: class SomeModel < ActiveRecord::Base end class MyClass attr_accessor :model def initialize(model) @model = model end end The class MyClass will then iterate over the Models attributes etc. Also I

[rspec-users] how to stop rspec from creating helper/view specs?

2012-09-14 Thread S Ahmed
I tried adding this to my application.rb: config.generators do |g| g.view_specs false g.helper_specs false end But it didn't stop the generator from creating view/helper specs. What am I doing wrong? Also also tried doing this the configuration section: config.view_specs = false config.he

[rspec-users] overview of how rspec was designed

2012-05-14 Thread S Ahmed
Other than jumping into the codebase myself, I was wondering if anyone has done a high-level (or better yet low level) write-up on how rspec works under the covers? ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listin

Re: [rspec-users] using rspec in a non-rails environment

2012-04-23 Thread S Ahmed
sky wrote: > On Mon, Apr 23, 2012 at 12:26 PM, S Ahmed wrote: > > My folder structure is as follows: > > > > /myapp/ > > /myapp/lib/class1.rb > > > > /myapp/rspec/spec_helper.rb > > /myapp/rspec/lib/class1_spec.rb > > > > My spec_helper ha

[rspec-users] using rspec in a non-rails environment

2012-04-23 Thread S Ahmed
My folder structure is as follows: /myapp/ /myapp/lib/class1.rb /myapp/rspec/spec_helper.rb /myapp/rspec/lib/class1_spec.rb My spec_helper has: require 'rubygems' require 'rspec' RSpec.configure do |config| end My class1_spec.rb has: require 'spec_helper' require '../../lib/class1' describ

Re: [rspec-users] how to refactor signin process for re-use?

2012-03-09 Thread S Ahmed
ext: > > shared_context :signed_in do > before do >sign_in(current_user) >controller.stub!(:current_user).and_return(current_user) > end > end > > On Thu, Mar 8, 2012 at 6:15 PM, S Ahmed wrote: > > In my authenticate_pages.spec (requests) I do the followi

[rspec-users] how to refactor signin process for re-use?

2012-03-08 Thread S Ahmed
In my authenticate_pages.spec (requests) I do the following to test if the signin worked: describe "with valid information" do #let(:account) { FactoryGirl.create(:account) } let(:user) { FactoryGirl.create(:user) } before do fill_in "Email", with: user.email fi

Re: [rspec-users] testing sessions

2012-03-04 Thread S Ahmed
Sun, Mar 4, 2012 at 1:34 PM, David Chelimsky wrote: > On Sun, Mar 4, 2012 at 7:40 AM, S Ahmed wrote: > > I want to test if my sessions logic works. > > > > Session: > > id > > user_id > > > > When I create a new session, if there was a previous se

[rspec-users] testing sessions

2012-03-04 Thread S Ahmed
I want to test if my sessions logic works. Session: id user_id When I create a new session, if there was a previous session row in the db with user_id = xxx, it should delete it first, then create a new row. How could I test this scenerio? So far I have: require 'spec_helper' describe Sessi

Re: [rspec-users] mimicking a logged in user

2012-03-03 Thread S Ahmed
12:35 PM, S Ahmed wrote: > > > I'm testing my controller, and confirming that a logged-in user can view > the page. > > > > I have a session_helper that does this: > > > > def signed_in? > > !current_user.nil? > > end > > > >

[rspec-users] mimicking a logged in user

2012-03-03 Thread S Ahmed
I'm testing my controller, and confirming that a logged-in user can view the page. I have a session_helper that does this: def signed_in? !current_user.nil? end And the current_user is set with: def user_from_remember_token remember_token = cookies[:remember_token] User.find_by_reme

[rspec-users] can I output the html of the page after calling click_button?

2012-03-01 Thread S Ahmed
I am not sure why my form submission is failing (request test). I am calling: # form is filled in a 'before do' block. it "should create an account" do expect { click_button "Create" }.to change(Account, :count).by(1) end Could I somehow view the HTML after the click_button call? Manually su

Re: [rspec-users] issues when trying to select an option in a drop down list

2012-03-01 Thread S Ahmed
ing.pry above that line, and then > run it, and then poke around in the repl and see if you've got the right > context. You did make the request to get that page, right? > > Ben > > On Wed, Feb 29, 2012 at 10:04 PM, S Ahmed wrote: > >> My html looks like: >

[rspec-users] tests using factorygirl

2012-02-29 Thread S Ahmed
I'm trying to use factory for a test case, but the model I am creating via the factory depends on another model, how do you setup a factory like this? Model Account has a location_id attribute (where Location is another model) So how do I set it? FactoryGirl. do location_id / en

[rspec-users] issues when trying to select an option in a drop down list

2012-02-29 Thread S Ahmed
My html looks like: Acura Honda Ford Toyota GM My requests spec looks like: before do select '7', :from => "account[car_type]" fill_in .. .. end I get the error message: Failure/Error: select '7', :from => "account[car_type]" Capybara::ElementNotFound: cannot select option

Re: [rspec-users] requests: is it possible to put the fill_in's into a method?

2012-02-26 Thread S Ahmed
ahh, nice makes sense thanks! On Sun, Feb 26, 2012 at 12:25 PM, Andrew Premdas wrote: > On 26 February 2012 16:36, S Ahmed wrote: > >> I'm testing my signup page, and I want to minimize the duplication of >> the fill_in code for filling in the form fields and testin

[rspec-users] requests: is it possible to put the fill_in's into a method?

2012-02-26 Thread S Ahmed
I'm testing my signup page, and I want to minimize the duplication of the fill_in code for filling in the form fields and testing how my page reacts when someone forgets to enter input. fill_in "", with: "abc123" Any tricks of doing this? Say I have 10 fill_in calls, so say I want to test to

[rspec-users] requests versus cucumber

2012-02-13 Thread S Ahmed
For those of you who have used both rspec requests and cucumber, could you summarize the main differences between the two? Do they both serve the same purpose but with different implementation styles or they really aren't the same thing? I havent' used requests before, but I like the idea of bein

Re: [rspec-users] does jruby rspec have to use selenium?

2012-01-16 Thread S Ahmed
an 16, 2012 at 10:51 PM, Justin Ko wrote: > > On Jan 16, 2012, at 7:35 PM, S Ahmed wrote: > > > With jruby and rspec requests, do you have to use selenium webdriver? > > > > I'm confused, with ruby and rubyonrails using cucumber with capybara, I > didn't have

[rspec-users] does jruby rspec have to use selenium?

2012-01-16 Thread S Ahmed
With jruby and rspec requests, do you have to use selenium webdriver? I'm confused, with ruby and rubyonrails using cucumber with capybara, I didn't have to set the default driver, what was it using and can i use that with jruby? Things just worked w/o me even having to know about it :) _

[rspec-users] rspec and requests, and folders conventions

2012-01-16 Thread S Ahmed
I'm trying to run rspec requests, using jruby, and I set the defaults in a env.rb file, but it doesn't seem to be loaded when I run the specs. My folder setup is: /spec/requests/ /spec/requests/section/section_spec.rb /spec/support/env.rb (where I configured selenium as the driver etc.) I also

Re: [rspec-users] "user" received unexpected message :created_at with (no args)

2011-06-29 Thread S Ahmed
Oh and I am grateful for your refactoring and explanations, simplies my code and tests (and understanding!) On Wed, Jun 29, 2011 at 3:19 PM, S Ahmed wrote: > Ok I got it working, and honestly I have no idea why it is working. > > There was a test below it which I modified (I had u

Re: [rspec-users] "user" received unexpected message :created_at with (no args)

2011-06-29 Thread S Ahmed
PM, S Ahmed wrote: > Your code worked, let me try and figure out why mine isn't working > > Your right it isn't exactly what I have, but pretty much everything is > identical except for the naming of the model. > > > On Wed, Jun 29, 2011 at 2:20 PM, David Chelim

Re: [rspec-users] "user" received unexpected message :created_at with (no args)

2011-06-29 Thread S Ahmed
Your code worked, let me try and figure out why mine isn't working Your right it isn't exactly what I have, but pretty much everything is identical except for the naming of the model. On Wed, Jun 29, 2011 at 2:20 PM, David Chelimsky wrote: > On Jun 29, 2011, at 12:21 PM,

[rspec-users] "user" received unexpected message :created_at with (no args)

2011-06-29 Thread S Ahmed
My method looks like: def self.can_do_this(user) return false if user.nil? ( (Time.now >= user.created_at) ? true : false ) end my spec: it "should allow you to do this" do user = stub("user") user.stub(:nil?).and_return(false) user.stub(:created_at).and_return(Time.now) res = Use

Re: [rspec-users] how to mock/stub when there are multiple model objects?

2011-06-23 Thread S Ahmed
Thanks. I'm trying this now on a Model that is using Mongoid. I have tried: it "should ..." do User.stub(:some_call).and_return(User.new(:name => "blah")) end And when running spec on this file I get: NoMethodError, undefined method "stub" for User:Class I also tried: User.stub!(:some_c

[rspec-users] how to mock/stub when there are multiple model objects?

2011-06-17 Thread S Ahmed
I'm a bit confused how to hook into a particular model object instance and mock/stub it? I understand how to hook into a class level method like: User.should_receive(:where).and_return() but what if my method looks like: def some_thing user = User.where("...") user2 = User.where("

Re: [rspec-users] How to mock when there seems to be a requirement for chained mocked calls?

2011-06-13 Thread S Ahmed
un 13, 2011 at 9:37 PM, David Chelimsky wrote: > On Jun 13, 2011, at 8:29 PM, S Ahmed wrote: > > "How to mock when there seems to be a requirement for chained mocked > calls?" > > There is no such requirement unless you are imposing it by your own design > decisions

[rspec-users] How to mock when there seems to be a requirement for chained mocked calls?

2011-06-13 Thread S Ahmed
I want to mock the following: MyModel.where(".").last I tried: MyModel.should_receive(:where).and_return(nil) but this of course doesn't match the expectation since the call to .last was not mapped in the mock code. How can I do this? ___ rspec-u

[rspec-users] rspec help for create user test

2011-05-19 Thread S Ahmed
My user controllers 'create' action looks like: def create @user = User.new(params[:user]) @user.user_name = params[:user][:user_name] @user.email = params[:user][:email] if @user.is_valid? @user.status = 2 @user.save! UserMailer.new_user(@user).deliver redirect_t

[rspec-users] using rspec and factory_girl, how to get around attributes that can't be set b/c of attr_accessible

2011-05-16 Thread S Ahmed
class User < ActiveRecord::Base attr_accessor :password, :password_confirmation attr_accessible :password, :password_confirmation, ... validates :password, :presence => true, :confirmation => true, :length => { :within => 6..20 } end factory_girl: Factory.define :user do |u| u.user_n

Re: [rspec-users] Cucumber and rspec, do cucumber step definitions use rspec?

2011-05-09 Thread S Ahmed
will it go and run spec's for you also? Correct me if I am wrong, but the cucumber step definitions do indeed use webrat to hit the pages and verify things in the view pages correct? On Mon, May 9, 2011 at 10:48 AM, Andrew Premdas wrote: > > > On 9 May 2011 15:00, S Ahmed wr

[rspec-users] Cucumber and rspec, do cucumber step definitions use rspec?

2011-05-09 Thread S Ahmed
I'm a bit confused as to how cucumber and rspec integrate (if they d at all?). You write a cucumber feature, and step definitions. Now in the step definitions, do you write rspec in the step definitions or do they somehow link to the spec's written elsewhere? __

[rspec-users] when mocking, does it scan the method being tested for outside calls?

2011-05-06 Thread S Ahmed
Say I want to test this method: def modify_user_status(user_id) .. .. user = User.find(user_id) .. .. end Now could I mock the call to User.find()? I'm just trying to understand, when I run the test, and say I mocked the call to User.find, then rspec realizes this and replaces

[rspec-users] api (class/method) renaming, will a simple controller test verify this?

2011-05-05 Thread S Ahmed
I want my tests to fail if I rename a method in my /lib folder in a rails app. Say I have a class like: /lib /lib/formatter.rb class Formatter def self.do_transforms(text) text end end And say I reference this in my HomeController's index action: def index text = params[:tex