Disabling non-available options in RSpec 2.6 - ruby

In my primary ~/.rspec file, I have the option --order default set up.
I've just started work on a Rails project that uses an older version of RSpec (I'm not sure exactly which of the RSpec gems in the gemfile is the key one, but all are 2.6.something)
When I run bundle exec rspec with the new project, it throws the exception invalid option: --order (OptionParser::InvalidOption).
I've been able to fix this by deleting the option from the main RSpec file, but obviously that's not really what I want to do. But what I've been able to find in RSpec's documentation about overriding locally all refers to either changing options or introducing new ones - not to ignoring them altogether.
The ./.rspec file in my project root has nothing but the option --color, but evidently that's not a command to use only that option.
Is there a way to tell it locally to ignore the line whose syntax it doesn't understand?
Thanks all.

You can use custom config file or set project's one explicitly
rspec spec/ --options .rspec
http://www.relishapp.com/rspec/rspec-core/v/2-10/docs/configuration/read-command-line-configuration-options-from-files#rspec-ignores-./.rspec-when-custom-options-file-is-used
It also ignores ~/.rspec not only ./.rspec as it specified in documentation

Related

Trying to understand the error

I was learning about the gem Rspec through a tutorial when this error came up.The last thing I typed in was
$ rspec spec spec\hello_world_spec.rb
I had only installed the Rspec gem and nothing else.
the output message from the cmd
Try to get rid of spec
rspec spec\hello_world_spec.rb
You're passing spec and spec\hello_world_spec.rb as arguments to rspec. These are interpreted as files to run, or directories to search through for files to run. Since you're already running in the spec\ directory, rspec is looking for spec\spec\ and spec\spec\hello_world_spec.rb, which don't exist. Try running that from one directory up (in a typical ruby project, the "root" of your project) and it should run.
i.e. Instead of:
\rspec_tutorial\spec>rspec spec spec\hello_world_spec.rb
try:
\rspec_tutorial>rspec spec spec\hello_world_spec.rb
Also, as #Ursus points out, running rspec spec spec\hello_world_spec.rb is redundant. Rspec will search through spec\ for files to run and will run hello_world_spec.rb automatically since it's under spec. If you only want to run hello_world_spec.rb–which seems to be your intent–then drop the spec from the command, per #Ursus' answer.

RSpec basics: bin/rspec --format doc

I've installed RSpec on a win7 lappy and am following along the http://rspec.info/ homepage tutorial to make sure everything works. If I am reading their demo correctly bin/rspec --format doc should run the specification test file.
Instead, I get a system prompt for a text editor... ? I am confused.
Any explanation of what is going on or guidance about how to get my RSPEC configuration working in accordance to the makers homepage would be great.
FWIW Ruby 2.2.5p319, Bundler version 1.13.1 and gem -v tells me 2.6.7 (originally I had 2.4 but that is broken on windows, so I upgraded according to http://guides.rubygems.org/ssl-certificate-update/) Also, I have basic RSpec functionality and have completed the tutorial here: https://www.tutorialspoint.com/rspec/rspec_writing_specs.htm
Ah, I figured out what I need to do... I just need to explicitly call ruby:
ruby bin/rspec --format doc
...and the test gets run - YaY!
Per #JörgWMittag, I confirmed my Environment Variable Path to make sure ruby.exe was in there (C:\Ruby22\bin;).
Then looking at my Program Defaults, I thought that maybe I could tell win7 to associate any file named "rspec" with ruby.exe per https://support.microsoft.com/en-us/help/18539/windows-7-change-default-programs ...but I couldn't actually add file type "extensions" or "protocols" - I could only change the association of existing ones, but .rb and .rbw were in there... Maybe there is a way to do this manually, but I am not a windows expert.
Thinking on all this it occurred to me that I just needed to explicitly tell ruby to ingest the command... Heh.
I apologize if this is off-topic.

How do I pass two build parameters to bundle config?

I'm trying to configure bundler such that building the mysql2 gem will pass the necessary parameters to extconf. Problem is, I can't figure out how to pass more than one parameter.
In my Gemfile, I just have:
gem mysql2, '= 0.3.11'
(There is some problem with the latest version which prevents compiling it at all, so I'm using 0.3.11 based on a recommendation I found on another post somewhere around here.)
I tried this:
bundle config build.mysql2 --with-mysql-include=C:\DevEnv\Tools\Ruby\mysql-connector-c-noinstall-6.0.2-winx64\include --with-mysql-lib=C:\DevEnv\Tools\Ruby\mysql-connector-c-noinstall-6.0.2-winx64\lib
I also tried quoting the parameters into a single parameter:
bundle config build.mysql2 "--with-mysql-include=C:\DevEnv\Tools\Ruby\mysql-connector-c-noinstall-6.0.2-winx64\include --with-mysql-lib=C:\DevEnv\Tools\Ruby\mysql-connector-c-noinstall-6.0.2-winx64\lib"
I can tell it isn't working because gem is showing me the command-line which is actually being used, and then the build fails because it can't provide the lib):
C:/DevEnv/Tools/Ruby/Ruby200-x64/bin/ruby.exe extconf.rb --with-mysql-include=C:\DevEnv\Tools\Ruby\mysql-connector-c-noinstall-6.0.2-winx64\include
If I provide just the --with-mysql-lib parameter or swap the order of the parameters, the build passes on looking for the lib but fails on a missing include instead.
If I pass the same flags to gem directly, that works fine. But that won't be terribly great when it comes time to deploy.
How are other people doing this?
PS a binary DLL would have been nice, but I guess they stopped doing that.
For the next poor sap that has to deal with this, the answer is a lot of quoting:
bundle config build.mysql2 "--with-mysql-include=\"C:\DevEnv\Tools\Ruby\mysql-connector-c-noinstall-6.0.2-winx64\include\" --with-mysql-lib=\"C:\DevEnv\Tools\Ruby\mysql-connector-c-noinstall-6.0.2-winx64\lib\""
bundle config --local --with-mysql-include 'C:\INC_PATH\include'
bundle config --local --with-mysql-lib 'C:\LIB_PATH\lib'
The above will store configuration directives in current directory in .bundle/config file. After you have these two directives run, try normal build install. Hope it helps.
More info.

After what version of rspec was the support for reading .rspec added

I am trying to add "--require spec_helper" to .rspec file based on a suggestion in https://stackoverflow.com/a/5097049/371572
I tried to create .rspec file in the root of the webapp and added the above line but it doesn't seem to work. Neither does added to spec/spec.opts
I realized that the version of rspec we are using is 1.3.2 and rspec-rails version of 1.3.4. So I was wondering if there is a support for reading .rspec file in this version. How do I look up or verify that.
P.S. I run specs using bundle exec rake spec
The .rspec file has always been supported in RSpec 2 (the oldest entry in its history, for 2.0.0.beta.22, references it, and it was originally added in fd0398e as .rspecrc and renamed to .rspec in beaf23b). It has never been supported in RSpec 1.
That said, RSpec 1.x is massively old. I’d strongly suggest you attempt to migrate to RSpec 2 (which came out nearly 3 years ago).

No colors when using autospec

When I'm using autospec to test a non-Rails Ruby project, I always have trouble getting my tests to show up red or green.
When I run a regular 'spec spec/ --color' command I get normal red/green responses. I've tried putting all sorts of commands in the .autotest file and I can't get that to work.
Also, in my Rails projects, I don't get this problem.
Note:
I do have the ZenTest(4.2.1) and redgreen (1.2.2) gems installed.
I'm currently trying to get it working with this project: http://github.com/coreyhaines/kata-number-to-led
Autospec reads a configuration file at spec/spec.opts for options. Make sure rspec can find this file and that it has the --color option (or --colour for our British friends).

Resources