[Maybe this belongs on howto but I can't post there]
My goal was to be able to run the test suite on a Mac. In the end, this took about 6 hours to setup, so I figure I will document the pain here in the hopes that it helps someone. This is for Mac OS X 10.9.3, heaven knows if it will work for any other version.
I assume you don't want to affect your system more than necessary (especially globally) and I'm using tcsh, so adjust for bash.
Things to do:
Install MacPort http://www.macports.org/install.php - installing MacPort can take a long time, so be patient.
Clone discourse into ~/unix/discourse
cd ~
mkdir ~/unix
cd ~/unix
git clone git://github.com/discourse/discourse/git
cd discourse
Set gems to be installed for this user only
echo install: --user-install >> ~/.gemrc
echo update: --user-install >> ~/.gemrc
Setup environment variables:
setenv PATH ~/.gem/ruby/2.0.0/bin:/opt/local/lib/postgresql91/bin:$PATH
setenv ARCHFLAGS "-arch x86_64"
setenv RAILS_ENV test
Update MacPorts
sudo port selfupdate
sudo port upgrade outdated
Install bundler
gem install bundle
rehash
Install Xcode.app
and command line tools:
xcode-select --install
Install libraries
sudo port install libxml2 libxslt
Install postgresql and redis
sudo port install postgresql91 postgresql91-server redis
Setup postgresql
rehash
sudo mkdir -p /opt/local/var/db/postgresql91/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql91/defaultdb
sudo su postgres -c '/opt/local/lib/postgresql91/bin/initdb -D /opt/local/var/db/postgresql91/defaultdb'
In a separate Terminal window, start postgres
sudo -u postgres /opt/local/lib/postgresql91/bin/postgres -D /opt/local/var/db/postgresql91/defaultdb
Start redis:
sudo port load redis
Setup redis:
rehash
mkdir /tmp/redis
chmod 777 /tmp/redis
redis-cli flushall
redis-cli
127.0.0.1:6379> CONFIG SET dir /tmp/redis
OK
127.0.0.1:6379> CONFIG SET dbfilename temp.rdb
OK
quit
redis-cli flushall
Install the discourse gem dependencies (into ~/unix/bundler)
bundle install --path ~/unix/bundler
This will take a long time, so be patient again.
Create the postgres user (change YOURUSERNAME to your user name
sudo -u postgres /opt/local/lib/postgresql91/bin/createuser YOURUSERNAME
Shall the new role be a superuser? (y/n) y
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) y
The default postgres template may be ASCII and needs to be UTF8, so fix this (see http://stackoverflow.com/questions/16736891/pgerror-error-new-encoding-utf8-is-incompatible) (you can try without this, it will depend on your system settings as to whether the default is UTF8 or ASCII).
psql -U postgres template1
CREATE DATABASE temp WITH TEMPLATE = template0 ENCODING = 'UNICODE';
\c temp
DROP DATABASE template1;
CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
\c template1
DROP DATABASE temp
VACUUM FREEZE;
^D
Create the test database
bundle exec db:drop db:create db:migrate
And now run the test:
bundle exec rake spec
Wait about five minutes for the tests to run.
If you get problems installing nokogiri, you probably have old or outdated versions or architectures of libxml2, libiconv or libxslt, consider trashing any old versions and reinstalling from macports.
If you get problems about missing categories table, you probably have not set the RAILS_ENV to test.
Good luck!