Forum: RSpec Problem while generating rspec model in Rails Project

01ac5133869dbe739fe5745aacc15900?d=identicon&s=25 Ninad Pol (ninad)
on 2009-06-12 12:35
Attachment: rspec_model_generation.JPG (70 KB)
Hi,

I am new to testing and Rspec. I have one rails project created on my
machine.
In this project under \app\models i have a file called "client.rb" which
has been already created. Now i want to generate spec file for this
model for which i am using command:

ruby script/generate rspec_model Client

Now with this command along with spec file, a file called "client.rb"
will also be generated under \app\models. But in my case since the file
"client.rb" is already present,with above command i am getting following
message:

---------------------------------------------------
>ruby script/generate rspec_model Client

The name 'Client' is either already used in your application or reserved
by Ru
by on Rails.
Please choose an alternative and run this generator again.

Suggestions:

customer
node
guest

----------------------------------------------------
Platform and Version details:

Windows xp-professional
Ruby 1.8.6
Rails 2.3.2
Gem 1.3.1
----------------------------------------------------
I have also attached console snapshot for same.

I haven't found any help related to this.Ideally in such cases it should
ask for the message regarding "whether you want to overwrite file
client.rb ? "

So can anybody please help me out regarding this issue. whether this is
related to version problem or what else earliest?
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-06-12 16:15
(Received via mailing list)
On Fri, Jun 12, 2009 at 5:35 AM, Ninad Pol<lists@ruby-forum.com> wrote:
>
> by on Rails.
>
>
> So can anybody please help me out regarding this issue. whether this is
> related to version problem or what else earliest?

I'm not sure where this message is coming from but it's not coming
from rspec. Have you tried generating with the rails generator?

ruby script/generate model Client

Does that give you the same error?
01ac5133869dbe739fe5745aacc15900?d=identicon&s=25 Ninad Pol (ninad)
on 2009-06-15 08:42
Thanks for your reply.

No, above command does not give me same error. However it creates only
the model file under \app\models and asks whether to overwrite it. But
my aim is to create rspec file under \spec\models with the actual model
file created under \app\models remaining unchanged. So using the rails
generator does not meet my objective and i have to use rspec generator
to meet the requirement.

Ideal schenario should be that rspec generator creates the desired rspec
file under \spec\models and while creating actual model file under
\app\models it should ask for whether to overwrite it. I am not getting
this schenario may be because i am missing something.It would be really
helpful if you could help me out in this.


David Chelimsky wrote:
> On Fri, Jun 12, 2009 at 5:35 AM, Ninad Pol<lists@ruby-forum.com> wrote:
>>
>> by on Rails.
>>
>>
>> So can anybody please help me out regarding this issue. whether this is
>> related to version problem or what else earliest?
>
> I'm not sure where this message is coming from but it's not coming
> from rspec. Have you tried generating with the rails generator?
>
> ruby script/generate model Client
>
> Does that give you the same error?
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-06-15 14:41
(Received via mailing list)
On Mon, Jun 15, 2009 at 1:42 AM, Ninad Pol<lists@ruby-forum.com> wrote:
> Thanks for your reply.
>
> No, above command does not give me same error. However it creates only
> the model file under \app\models and asks whether to overwrite it. But
> my aim is to create rspec file under \spec\models with the actual model
> file created under \app\models remaining unchanged. So using the rails
> generator does not meet my objective and i have to use rspec generator
> to meet the requirement.

I wasn't trying to meet your requirement with this - just trying to
narrow down the problem.

> Ideal schenario should be that rspec generator creates the desired rspec
> file under \spec\models and while creating actual model file under
> \app\models it should ask for whether to overwrite it. I am not getting
> this schenario may be because i am missing something.It would be really
> helpful if you could help me out in this.

The rails code that triggers this will always raise this error if the
Client constant (in your case) is already defined. This normally
doesn't conflict with files in your app because they are not loaded
when you run generators. So it seems that something other than
app/models/client.rb is getting loaded that defines the Client
constant (either a class or a module).

Do you have any plugins that define a Client? Or perhaps you've got
some extension in the lib directory?
01ac5133869dbe739fe5745aacc15900?d=identicon&s=25 Ninad Pol (ninad)
on 2009-06-15 15:04
I think this problem is not related any plugin (that define a client)
simply because if i try it with any other ruby file(other than
Client.rb) also i am facing same problem.And what do you mean by some
extension in the lib directory?


David Chelimsky wrote:
> On Mon, Jun 15, 2009 at 1:42 AM, Ninad Pol<lists@ruby-forum.com> wrote:
>> Thanks for your reply.
>>
>> No, above command does not give me same error. However it creates only
>> the model file under \app\models and asks whether to overwrite it. But
>> my aim is to create rspec file under \spec\models with the actual model
>> file created under \app\models remaining unchanged. So using the rails
>> generator does not meet my objective and i have to use rspec generator
>> to meet the requirement.
>
> I wasn't trying to meet your requirement with this - just trying to
> narrow down the problem.
>
>> Ideal schenario should be that rspec generator creates the desired rspec
>> file under \spec\models and while creating actual model file under
>> \app\models it should ask for whether to overwrite it. I am not getting
>> this schenario may be because i am missing something.It would be really
>> helpful if you could help me out in this.
>
> The rails code that triggers this will always raise this error if the
> Client constant (in your case) is already defined. This normally
> doesn't conflict with files in your app because they are not loaded
> when you run generators. So it seems that something other than
> app/models/client.rb is getting loaded that defines the Client
> constant (either a class or a module).
>
> Do you have any plugins that define a Client? Or perhaps you've got
> some extension in the lib directory?
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-06-15 15:32
(Received via mailing list)
On Mon, Jun 15, 2009 at 8:04 AM, Ninad Pol<lists@ruby-forum.com> wrote:
> I think this problem is not related any plugin (that define a client)
> simply because if i try it with any other ruby file(other than
> Client.rb) also i am facing same problem.

So if you do this:

rails widgets
cd widgets
script\generate model widget
script\generate rspec
script\generate rspec_model widget

The last command tells you that Widget is already defined?

> And what do you mean by some extension in the lib directory?

I mean that you have a file in the lib directory in your Rails project
that defines a client. I believe that loading the rails env (which
happens when you run script\generate) loads the lib directory, so if
you have a file in there that defines Client, then you'd run into this
problem.
01ac5133869dbe739fe5745aacc15900?d=identicon&s=25 Ninad Pol (ninad)
on 2009-06-30 14:11
David Chelimsky wrote:
> On Mon, Jun 15, 2009 at 8:04 AM, Ninad Pol<lists@ruby-forum.com> wrote:
>> I think this problem is not related any plugin (that define a client)
>> simply because if i try it with any other ruby file(other than
>> Client.rb) also i am facing same problem.
>
> So if you do this:
>
> rails widgets
> cd widgets
> script\generate model widget
> script\generate rspec
> script\generate rspec_model widget
>
> The last command tells you that Widget is already defined?
>
>> And what do you mean by some extension in the lib directory?
>
> I mean that you have a file in the lib directory in your Rails project
> that defines a client. I believe that loading the rails env (which
> happens when you run script\generate) loads the lib directory, so if
> you have a file in there that defines Client, then you'd run into this
> problem.

I am so sorry for not being replying for so long.I was busy working with
some other things and kept aside RSPEC. Above command does not gave me
any problem for "widgets" and model with name "widget" was created. But
in my project i am still getting the same problem as mentioned earlier.
This topic is locked and can not be replied to.